0

I opened a new window by window.open in JavaScript, the probleme that it work just after refresh

    var url=document.getElementById("largeImage").getAttribute("href");

   $("#largeImage").click(function(e){ e.preventDefault();
   var win=window.open(url);



  });
hind
  • 11
  • 5

2 Answers2

1

Option 1, JavaScript approach

This will work

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

You can then use it like this:

<div onclick="openInNewTab('www.test.com');">Something To Click On</div>

Reference, and more info, here: http://www.tutsplanet.com/open-url-new-tab-using-javascript-196/

Option 2, HTML approach

Really simple, just use the target='_blank' to your anchor link, e.g:

<a target="_blank" href="http://your_url_here.html">Link</a>
Alicia Sykes
  • 5,997
  • 7
  • 36
  • 64
0

Why don't you just add an anchor around your image and open a new tab by using the href-attribute?

Example:

<a href="url"  target="_blank" >
<img />
</a>
Locke Lamora
  • 63
  • 1
  • 9