yellinas

Q: window.open(url) called onclick opens in 2 new windows instead of 1 window. This piece of code works fine in other browsers

window.open(url) called onclick opens in 2 new windows instead of 1 window. This piece of code works fine in other browsers. Is there any other specific code to be used in jquery script for opening in one tab?

Posted on Oct 7, 2015 5:20 AM

Close

Q: window.open(url) called onclick opens in 2 new windows instead of 1 window. This piece of code works fine in other browsers

  • All replies
  • Helpful answers

  • by yellinas,

    yellinas yellinas Oct 7, 2015 5:49 AM in response to yellinas
    Level 1 (0 points)
    Oct 7, 2015 5:49 AM in response to yellinas

    Code used in jsp: 

     

    <li class="gallery">Gallery</li>

     

    Code used in external js:

     

    $('.gallery').on('click', function() {

      if (!window.location.origin) {

       window.location.origin = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port: '');

      }

      var newUrl = window.location.origin;

      window.open(newUrl+'/gallery');

      return false;

    });

     

    Help Needed: Please Let me know if there is an alternative solution.

    My requirement is to open the base url appended with gallery in a new tab.