Reputation: 11
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);
});
Upvotes: 0
Views: 2449
Reputation: 63
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>
Upvotes: 0
Reputation: 7117
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/
Really simple, just use the target='_blank'
to your anchor link, e.g:
<a target="_blank" href="http://your_url_here.html">Link</a>
Upvotes: 1