解决弹出的窗口window.open会被浏览器阻止的问题

来源:互联网 发布:拼多多是什么软件 编辑:程序博客网 时间:2024/05/23 00:46

遇到自动跳转时要弹出网页,就发现出现了问题。后发现有这样的情况:


//这样注册的脚本会被阻止: System.Web.UI.ScriptManager.RegisterStartupScript(this, this.GetType(), "js", "window.open('http://www.xxxxxxxxx.com');", true);

//客户端由用户触发的不会被阻止,即使设置阻止程序.obj.onclick=window.open("http://www.xxxxxxxxx.com")



1、放到连接里,然后用JS伪协议打开就好了

<a href='javascript:void window.open("x.html","x","resizable,width=600,height=450")'>不会被阻止</a>



2、登录窗口前一页Login0.aspx页面添加如下代码,
<a href="javascript:void window.open('Login.aspx','','width=1014px,height=703px,scrollbars=yes,left=0,top=0')">汽车租赁管理系统</a>


3、代码页添加
Response.Write("<script language='javascript'>window.open('Login.aspx','_self','')</script>");


4、在登录成功后
Response.Write("<script language='javascript'>window.open('Default.aspx','_blank','width=1014px,height=703px,scrollbars=yes,left=0,top=0');window.close();</script>");

5、

function openwin(url) {    var a = document.createElement("a");    a.setAttribute("href", url);    a.setAttribute("target", "_blank");    a.setAttribute("id", "openwin");    document.body.appendChild(a);    a.click();}

调用方式:
<input type="button" id="btn" value="百度" onclick="openwin('http://www.baidu.com');" />


来自:http://www.cnblogs.com/linyechengwei/archive/2011/03/23/1992434.html
           http://blog.csdn.net/daqiaonanlu2000/article/details/3721512


原创粉丝点击