Redirect to 2 pages

后端 未结 3 1067
臣服心动
臣服心动 2021-01-29 16:05

I have a PHP page and I want to redirect it first to a page (eg google.com) then to another page (eg bing.com).

To do this I\'m using the following:

head         


        
相关标签:
3条回答
  • 2021-01-29 16:48

    Well, maybe you would like to open 2 page at the same time. You can control it by javascript.

    Something like following code:

    var open_link_google = window.open('','_parent');
    open_link_google.location="http://www.google.com";
    
    var open_link_yahoo = window.open('','_blank');
    open_link_yahoo.location="http://www.yahoo.com";
    
    0 讨论(0)
  • 2021-01-29 16:49

    Something like following code:

    var open_link_google = window.open('','_parent');
    open_link_google.location="http://www.google.com";
    
    var open_link_yahoo = window.open('','_blank');
    open_link_yahoo.location="http://www.yahoo.com";
    
    0 讨论(0)
  • 2021-01-29 16:54

    I'm afraid the behavior as you've described it isn't possible. Exactly how would you expect this to work? How can a single browser window go to two pages at the same time? After all, the browser can't interpret your response headers until it receives the response. So there's no step in between the two lines of code you show, the browser receives them both in the same response.

    Thinking in terms of the request/response nature of the web, re-consider what you're trying to do in order to meet the need you're addressing. You stated that:

    I want to redirect it first to a page (eg google.com) then to another page (eg bing.com)

    There's an order of events there:

    1. User requests your page.
    2. Your page responds with a redirect to Page 1.
    3. User requests page 1.
    4. Page 1 responds.
    5. User requests Page 2.
    6. Page 2 responds.

    The step where you're looking to interject is between 4 and 5 above. Naturally, you can't modify or in any way control Google's response so you can't have a Page 1 that you don't control respond with a redirect to Page 2. (Indeed, even if they did, it's either content or a redirect... not both.)

    Off the top of my head there may be a workaround that might fit your needs. You could use frames to keep the user on your page while showing them the content of these other pages. Within your parent frame, which you would control, you can use JavaScript to set the various timers and other events which would direct the user from Page 1 to Page 2. (Is it instant? If so, why bother with Page 1 at all? Is it after a few moments? What should cause the redirect from Page 1 to Page 2?)

    0 讨论(0)
提交回复
热议问题