onClick="window.location -- trying to change to open link in new tab

user3711262 picture user3711262 · Jun 5, 2014 · Viewed 67.4k times · Source

Just trying to make this current code open the link in a new tab. Tried fixes found on this site for similar problems but haven't been able to get it working yet...

Current working code is:

<div onClick="window.location='https://URL';" class="element _element element-4"></div>

From researching, I've heard I should change it to onClick=window.open so I've changed this now to:

<div onClick=window.open(https://URL, Name) class="element _element element-4"></div>

Problem is, when I do change the code to window.open (as per above) clicking the link doesn't do anything at all now, let alone open in a new tab.

Is it something to do with /div? Do I need to alter the CSS or JS? Any help greatly appreciated! :)

Answer

SilenceHost picture SilenceHost · Jun 5, 2014

I guess that you've called the function in a wrong formula. Please check your function's parameters.

You can see more details here.

e.g. that works: onClick="window.open('yourURL');"