3

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

3 Answers3

1

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>
SekDinesh
  • 119
  • 8
1

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)

> JSFiddle - Example


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.

Maximilian Ast
  • 3,369
  • 12
  • 36
  • 47
0

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();"
Hearner
  • 2,711
  • 3
  • 17
  • 34