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

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


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

//客户端由用户触发的不会被阻止,即使设置阻止程序.
obj.οnclick=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="百度" οnclick="openwin('http://www.baidu.com');" />



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值