JavaEar 专注于收集分享传播有价值的技术资料

Javascript : Redirecting to another webpage through a popup

I'm quite bad with Javascript and I can't work out a solution I need help to. I'm having a website and I'm trying to make a redirection to another site, but through a popup.

Example :

<script>alert(This will prompt up the message)</scrip>


Like you can see I could simply use the second javascript to redirect the persons to another page, but due some reasons I can't use it as it will work only for half of the page(the script would be kinda 'sandboxed'), but if I'd make a popup(the first alert script) the second script would get out of the 'sandbox'. Is there anyone who has any ideas how I should implement this or can it be done otherwise with PHP or HTML?

Thanks for both of your replies yet these doesn't help me out yet although I'm quite sure that your help will. I'm having a MyBB forum and there's a shoutbox for it which I'm using. There's a command which will change the notice of the shoutbox and the command is as such /notice New notice | But I noted that the new notice can be changed with javascript and it'll work such as /notice js code here | Then I thought that what if I would make such a javascript that would redirect people to another webpage. As I'm having such a forum where it's needed to redirect from the main page to another one, I'd like to apply it. Then Staffs could do it in the forum very well, but there's a problem. by adding

/notice window.location=""; It'll affect only the shoutbox and shoutbox is being redirected to another webpage, but as an alert works for the whole forum I thought maybe I can redirect them to somewhere else with the alert. I want to know is it possible with just one script then Staffs would be able to do it. I know it's a serious security risk & it can be otherwise also, but I'd really like to experiment with it.

I hope someone can help. :)


  1. Use Confim and capture response to redirect. This popup will show two buttons - OK and Cancel.

    if(confirm("Popup Message")){
       window.location = "your intended destination";
    }else {//do nothing. This will fire if cancel is clicked.}
  2. 参考答案2
  3. This will do it, but what is the trigger that the user is going to perform to make the redirect happen? I would also say you will be WAY better off to use something like a jQuery dialog than an alert box In the head of the HTML

    function changePage(whereToGo, messageText)

    Then in the HTML itself

    <script>changePage("", "The message you want to show");</script>

    Note the complete of any error checks

    OK, then simply try this

    alert("Whatever you want to say") && window.location="";

    That will perform both actions in a single statement