DG3
DG3

Reputation: 5298

javascript open page in new tab with IE8

I am trying to open a simple link in a new tab. I have tried searching on google, and stackoverflow but the result says, we need to change settings in browser. Is there a way to do the same using javascript?

Here is the sample script

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript">
    function gotoNewtab(){
        document.forms[0].target="_blank";
        document.forms[0].method = "post";
        document.forms[0].action = "http://www.google.com";
        document.forms[0].submit();
    }
</script>
</head>

<body>
    <form name="frm">

        <p> click the below link to open the page in new tab </p>

        <p> <a href="##"
               onclick="javaScript:return gotoNewtab();">
            click here </a>
        </p>

    </form>   
</body>
</html>

Upvotes: 1

Views: 3022

Answers (3)

user13096898
user13096898

Reputation:

Write the following JavaScript code to open a new tab

window.open("http://www.targetdomain.com", '_blank');

If you want to use HTML to do it, write the following code:

<a href="http://www.targetdomain.com" target="_blank" rel="noopener noreferrer">Click here to open a new tab</a>

The noopener noreferrer attribute is to make sure the new tab doesn't mess around maliciously with the tab that opened it.

Upvotes: 1

Alex
Alex

Reputation: 2011

This behaviour is up the the specific browser settings. If the IE settings are set to tab-usage, they may be used, unless you specify that the links should open in a new window.

Upvotes: 0

SLaks
SLaks

Reputation: 887405

You don't need Javascript.

Just write

<a href="..." target="_blank">...</a>

Upvotes: 1

Related Questions