2015-06-19 77 views
0

我想加载页面时加载一个窗口。如果我尝试使用按钮打开窗口,代码将起作用。window.open在页面加载

我的IAM使用:

$(document).ready(function() { 
window.open ('http://google.com/', 'newwindow', config='height=720,width=1064, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, directories=no, status=no'); 
}); 

但是,它不会加载该窗口。

什么建议吗?

$(document).ready(function() { 
 
    window.open('http://google.com/', 'newwindow', config = 'height=720,width=1064, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, directories=no, status=no'); 
 
    $('.open_webmail').click(function() { 
 
    window.open('http://google.com/', 'newwindow', config = 'height=720,width=1064, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, directories=no, status=no'); 
 
    }); 
 
});
.open_webmail { 
 
    background-color: rgba(0, 124, 255, 0.7); 
 
    color: white; 
 
    font-size: 18px; 
 
    cursor: pointer; 
 
    -webkit-transition: all 550ms ease-in-out; 
 
    transition: all 550ms ease-in-out; 
 
    -moz-transition: all 550ms ease-in-out; 
 
    -o-transition: all 550ms ease-in-out; 
 
    -ms-transition: all 550ms ease-in-out; 
 
    display: inline-block; 
 
    position: fixed; 
 
    top: 0; 
 
    bottom: 0; 
 
    left: 0; 
 
    right: 0; 
 
    width: 200px; 
 
    height: 100px; 
 
    margin: auto; 
 
} 
 
.open_webmail:hover { 
 
    background-color: rgba(163, 0, 255, 0.7); 
 
    color: #c5c5c5; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
 
<button type="button" class="open_webmail">Login</button>

+0

在文档准备中添加'setTimeout' –

+0

你检查过弹出式窗口拦截器吗? – Su4p

+0

在新窗口中阻止打开'http://google.com/',因为请求是在未设置'允许弹出'权限的沙盒框架中制作的。“ –

回答

0

你可以尝试$(window).ready()检查您的弹出设置,也许是被封锁。因为你的代码在js小提琴上工作,我测试了它。

+0

谢谢,弹出窗口被阻止。有没有办法强制一个窗口不被阻止? – SNos

+0

在某些特定的浏览器中可能会有一些黑客行为,但一般规则是您无法绕过弹出窗口拦截器。我会建议您学习弹出窗口阻止程序如何从行为角度而不是技术上工作,并决定是否有必要强制用户出现不需要的弹出窗口。 http://stackoverflow.com/questions/2587677/avoid-browser-pop-up-blockers –