Amit Pal
Amit Pal

Reputation: 11052

How to open two link simultaneously in same tab without alerting or redirecting the first one

I have to open two link within a same tab using JavaScript and HTML:

<script type="text/javascript">
go(){
windows.open('http://www.yahoo.com');
}
</script>
a href="https://mail.google.com/mail/u/0/?logout&hl=en-GB"onclick = "go();">click me</a>   

What I want; when someone clicked on click me hyperlink then it should automatically runs sign out link of Gmail in background without any alert and redirect the automatically link which is in windows.open('http://yahoo.com');.

Upvotes: 0

Views: 1628

Answers (2)

Serge
Serge

Reputation: 1601

Algorithm would be:

  1. on click dynamically add a DOM element: 1x1 px image with its source set to GMail logout URL;
  2. wait a couple of seconds (timer);
  3. redirect to Yahoo.

Ok, whole test page content would be:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>test</title>
        <script type="text/javascript">
            function go() {
                var oImg=document.createElement("img");
                oImg.setAttribute('src', 'https://mail.google.com/mail/u/0/?logout');
                oImg.setAttribute('alt', 'na');
                oImg.setAttribute('height', '1px');
                oImg.setAttribute('width', '1px');
                document.body.appendChild(oImg);
                var t=setTimeout("goOn()",1500);
            }
            function goOn() {
                window.location.assign("http://yahoo.com");
            }
        </script>
    </head>
    <body>
    <p><a href="#" onclick="go();return false;">superlink</a></p>
    </body>
</html>

Have tested it in FFox - works fine : )

Upvotes: 2

Nicos Karalis
Nicos Karalis

Reputation: 3773

A best way is to create a assincronous call to logout from wherever you want

try use jQuery get method or this tutorial: http://www.xul.fr/en-xml-ajax.html

Upvotes: 0

Related Questions