javascripturlwindow.open

how to avoid about blank blocked while open a new tab


I am using the below code to open the page in a new window its working as expected but when I Right click "open in a new tab" its blocking with "about:blank#blocked", i am expecting the link to open in a new tab how to fix that?

<a href="javascript:;" style="color:red;" onclick="window.open('http://www.la.unm.edu',null,'left=50,top=50,width=700,height=500,toolbar=1,location=0,resizable=1,scrollbars=1'); return false;">Limk</a>


Solution

  • As stated by @Lain, just fill in the href attribute.

    <a href="http://www.la.unm.edu" style="color:red;" onclick="window.open('http://www.la.unm.edu',null,'left=50,top=50,width=700,height=500,toolbar=1,location=0,resizable=1,scrollbars=1'); return false;">Limk</a>

    Working Sandbox Demo (adding this to code snippet, because code snippet doesn't allow clicking links offsite)

    If you want to completely control the context menu actions, so that "Open in a New Tab" behaves identically to window.open(), then you should probably look at this answer: How to add a custom right-click menu to a webpage?.

    Why are you getting about:blank#blocked? Well, about:blank is just a blank page, and when you right click an element, and click something in the context menu, that does not fire the onClick event. So, it just shows a blank page.

    Why does it say #blocked, then, too? Probably because href contains "javascript", and the browser is trying to stop malicious code from executing. There are few resources explaining this, but AskLeo.com says...

    “about:blank#blocked” is sometimes displayed as the result of security software blocking access to something.