打开新标签页时如何避免空白被阻塞

how to avoid about blank blocked while open a new tab

我正在使用下面的代码在新的 window 中打开页面,它按预期工作,但是当我右键单击“在新选项卡中打开”时,它被“about:blank#blocked”阻塞,我期待 link 在新标签页中打开如何解决这个问题?

<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>

如@Lain所述,只需填写href属性即可。

<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(将此添加到代码片段中,因为代码片段不允许点击异地链接)

如果您想完全控制上下文菜单操作,以便“在新选项卡中打开”的行为与 window.open() 相同,那么您可能应该看看这个答案:How to add a custom right-click menu to a webpage?

你为什么得到 about:blank#blocked?好吧,about:blank 只是一个空白页面,当您右键单击一个元素并在上下文菜单中单击某些内容时,不会触发 onClick 事件。所以,它只是显示一个空白页。

那为什么也说#blocked呢?可能是因为 href 包含“javascript”,浏览器试图阻止恶意代码的执行。解释这一点的资源很少,但是 AskLeo.com 说...

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