0

On launching a window using window.open(), a new instance of browser is getting launched on button click every time, even if the calling function is having named window.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <script type="text/javascript">
        function OpenNamedWindow() {
            var w2 = window.open("http://stackoverflow.com", "myWindow", "width=500px;height=500px");
        }
    </script>
    <input type="button" onclick="OpenNamedWindow();" value="Launch App" />
</body>
</html>

After launching the page when I try to access window.name, it shows empty.

I did some search and looks like cross domain is causing the issue.

How can I load the page in same instance instead of launching a new browser window all the time?

Jed Fox
  • 2,979
  • 5
  • 28
  • 38
Jha.prashant
  • 233
  • 1
  • 8

2 Answers2

1

This is a trick

function openInNewTab(url) {
  var win = window.open(url, '_blank');
  win.focus();
}

But even this, perhaps should not work in all browser depending on users configuration

This topic is still here in stackoverflow.

try to check it by yourself at the following link

Open a URL in a new tab (and not a new window) using JavaScript

Community
  • 1
  • 1
0

It opens only one window at a time:

var window_name = null; // global
...
function open_new_window() {
    if (window_name && !window_name.closed) {
        window_name.close();

    window_name = window.open(....);
}
Thevs
  • 3,189
  • 2
  • 20
  • 32