javascript - window.open sends the current window to 0 -


on page (we'll call it: domain.com/subdirectory/page.html) have link this: <a href="javascript:window.open('someurl','_blank');">link</a>

the new window opens perfectly, problem is, pre-existing window gets redirected {domain.com}/{subdirectory}/0 , can't figure out why it's adding 0 subdirectory , trying go there.

i have tried moving window.open onclick , making href "void(0)" , changed span onclick, same results no matter option try. want new window pop , nothing happen page you're on.

the same thing happens in ie9 , in chrome.

the reason using window.open , not target="_blank" because want remove menu , other stuff window save space.

answer discovered
when summarized problem, simplified code make impossible answer (not intention of course). apologize this.

here's actual window.open command (minus url): window.open('[hidden url]'_blank',height='400px',width='450px',location=0,menubar=0,resizable=0,status=0,titlebar=0,toolbar=0);

the problem "location=0". when read tutorial on window.open, said set 0 if didn't want url shown. personally, didn't care, figured, more real estate information display better. turns out, "location" url , not boolean property.

once removed "location=0" began functioning expected/desired.

thank trying help.

use onclick , return false event handler:

<a href="#" onclick="window.open('someurl','_blank'); return false;">link</a> 

i recommend separating javascript html. if have 1 link like:

<a id="linkid" href="someurl" target="_blank">link</a> 

then somewhere before closing </body> tag , after link tag:

<script>   document.getelementbyid('linkid').onclick = function(){       window.open('someurl','_blank');       return false;   } </script> 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -