2014-02-26 69 views
0

我在我的页面正文中有以下代码。它应该在新窗口中打开登录页面,然后关闭当前窗口。javascript window.open无法正常工作时_blank

<script type="text/javascript"> 
    window.open('/login', '_blank'); 
    window.close(); 
</script> 

如果我改变_blank_self但这不是我想要的它的工作原理!

任何想法?

+0

window.open默认工作功能的新窗口/标签 – Lab

回答

0

问题

恐怕你浏览器不允许这样的脚本阻止弹出窗口


解决方案

您的浏览器(和他的弹出窗口拦截器),如果用户事件(如点击)的加工过程中使用通常只允许window.open。所以你应该尝试重新设计你的脚本行为。


也许另一种有趣的方法

也许你应该考虑使用一个不错的弹出式的jQuery插件像Fancybox。这不会被您的浏览器阻止,因为它不是真实弹出。


你可以写window.open('/login')而不是window.open('/login', '_blank')

0

window.open()只会打开新的窗口,没有必要的_blank_self

window.open('/login'); 
0

从技术文档:

window.open(URL,name,specs,replace) 

所以关于名字的说法:

Optional. Specifies the target attribute or the name of the window. The following values are supported: 
_blank - URL is loaded into a new window. This is default 
_parent - URL is loaded into the parent frame 
_self - URL replaces the current page 
_top - URL replaces any framesets that may be loaded 
name - The name of the window (Note: the name does not specify the title of the new window) 

所以你不需要_blank因为默认的