Reputation: 33
This is the code:
<a href="FAKE_URL" onclick="document.location.href = 'REAL_URL'; return false;">
<img src="IMAGE"></a>
I have already tried:
<a href="FAKE_URL" onclick="document.location.href = 'REAL_URL'; return false;" target="_blank">
<img src="IMAGE"></a>
but not working
Upvotes: 3
Views: 6471
Reputation: 3497
you can use window.open('url','_blank')
to open after the onclickevent a new tab:
<a href="https://google.com" onclick="window.open('https://youtube.com','_blank'); return false;">click here for a new tab</a>
or you can use window.open('url','','width=,height=')
to open a new window:
<a href="https://google.com" onclick="window.open('https://youtube.com','','width=800,height=700'); return false;">click here for a new window...</a>
In this example it will open youtube (REAL_URL
) instead of google (FAKE_URL
)
Explanation:
Your mistake was that the add of target="_blank"
changes the behaviour of your <a href="..."></a>
, but not your document.location.href='...'
. So without the document.location.href='...'
it would open the FAKE_URL
in a new tab.
Upvotes: 1
Reputation: 2709
To open file in a new window, use
onclick="window.open('yourfile.html','','width=750px,height=1000px,left=150,top=0,toolbar=no,status=no,resizable=no,titlebar=no').focus();"
Upvotes: 0
Reputation: 119
Try this:
<a href="../html-link.html" target="popup" onclick="window.open('../html-link.html','name','width=600,height=400')">Open page in new window</a>
Upvotes: 1