Skip to content Skip to sidebar Skip to footer

How To Open A New Tab And Change The Current Page

cURL library? It lets you send POST and GET requests and parse the results in PHP.

To answer the question in the title, if you simply want to open two pages with one click, you could do it like this (excuse the inline javascript):

<a
    href="http://www.google.com"
    target="_blank"
    onclick="document.location.href='http://www.yahoo.com'"
>Click here to open Googlein a newwindow and yahoo inthiswindow</a>

Solution 2:

<formid="frm_1"name="frm_1"target="_self"method="POST"action="local_page.php" ><inputtype="hidden"name="vital_param"value="<?=$something?>"></form><formid="tgt_1"name="tgt_1"target="_blank"method="POST"action="http://stackoverflow.com/" ></form><buttontype="submit"onclick="test(event, '1'); " >Click Here</button><script>functiontest(event, id){
    window.open( document.getElementById("tgt_"+id).action, "_blank");
    setTimeout('document.getElementById("frm_'+id+'").submit();', 1000);

    returntrue;
    }
</script>

tgt kept as source of target url, could be array or attribute. Without setyTimeout() browser stays on current page (FF/IE).

Solution 3:

You should use the window.open to open the new page and then submit the tabchange e.g.

<formid="frm_1"name="frm_1"target="_self"method="GET"action="local_page.php" ></form><aonclick="test(event, '1'); "href="#" >Click Here</a><script>functiontest(event, id){
        window.open("http://stackoverflow.com/", "_blank");
        document.getElementById("tgt_"+id).submit();
    }
</script>

Solution 4:

Use the ‘target’ attribute on the form elements to make them submit to eg. a new window or an iframe, without reloading the current page (breaking any other form submissions).

Your a.onclick should also return false to stop the href link being followed. Really this should be a button not a link.

Avoid this sort of stuff unless you've got a specific good reason. Depending on what you're actually trying to do there is usually a better way.

Post a Comment for "How To Open A New Tab And Change The Current Page"