Skip to content Skip to sidebar Skip to footer

Opening Only One Instance Of Url Using Window.open

I am working on an asp.net web page which has a hyperlink. when ever that hyperlink is clicked, a new browser window is opened using javascript window.open. I want that If user cli

Solution 1:

Try

window.open("<url>", "<window name>");

This should always open in the same window. See reference.

Solution 2:

HTML:

<a href="http://www.someurl.com" onclick="openwindow.call(this); return false;">open window</a>

var wins = {};
functionopenwindow(){
    var url = this.href;
    if(typeof wins[url] === 'undefined' || wins[url].closed)
        wins[url] = window.open(url);
}

Solution 3:

<script>var windowObjectReference = null; // global variablefunctionopenFFPromotionPopup() {
  if(windowObjectReference == null || windowObjectReference.closed)
  /* if the pointer to the window object in memory does not exist
     or if such pointer exists but the window was closed */

  {
    windowObjectReference = window.open("http://www.spreadfirefox.com/",
   "PromoteFirefoxWindowName", "resizable,scrollbars,status");
    /* then create it. The new window will be created and
       will be brought on top of any other window. */
  }
  else
  {
    windowObjectReference.focus();
    /* else the window reference must exist and the window
       is not closed; therefore, we can bring it back on top of any other
       window with the focus() method. There would be no need to re-create
       the window or to reload the referenced resource. */
  };
}
</script><ahref="javascript:void(0);"onclick="openFFPromotionPopup()">click here</a>

Check the reference https://developer.mozilla.org/en-US/docs/Web/API/window.open

Solution 4:

To open only one instance of a popup window in an HTML page, use the windowName parameter of the window.open method. For example

window.open('http://www.abc.com') 

will open a new window each time the user clicks the link containing the window.open code. In constrast,

window.open('http://www.abc.com','abc') 

will open only one instance of the window, no matter how many times users click the link.

you can also use focus function as used below

<scriptlanguage="javascript"type="text/javascript"><!--
function popitup(url) {
    newwindow=window.open(url,'name','height=200,width=150');
    if (window.focus) {newwindow.focus()}

      if (!newwindow.closed) {newwindow.focus()}
    return false;
}

// --></script>

Edit 1

<aonclick="return addClick()"href="javascript:void(0)">New</a>

and here is the code I am using:

functionaddClick() {
    varID = jQuery("#ID").val();
    varPSSWD = jQuery("#PSSWD").val();
    varACCID = jQuery("#ACCID").val();
    varPASSWDINT = jQuery("#PASSWDINT").val();

    window.open("LoginAPI?ID=" + encodeURIComponent(ID) + "&PSSWD=" + encodeURIComponent(PSSWD) + "&ACCID=" + encodeURIComponent(ACCID) + "&PASSWDINT=" + encodeURIComponent(PASSWDINT) + "", "LoginAPI");
    returnfalse;
}

Post a Comment for "Opening Only One Instance Of Url Using Window.open"