window.open参数说明及解决弹出窗口被拦截的问题

window.open(url, [name], [configuration]) 参考:MDN的window.open 有其他参数可具体了解
其中:
url, 为要新打开页面的url
name,为新打开窗口的名字,可以通过此名字获取该窗口对象
configuration,为新打开窗口的一些配置项,比如是否有菜单栏、滚动条、长高等等信息

属性说明
_blank默认的,在新窗口打开链接的url
_self在当前窗口打开链接url
_parent在父窗口打开链接url
_top在顶级窗口打开url
framename在指定的框架中打开链接url

只要配置了configration,所有浏览器都是新窗口打开链接url

动态传入已获取的html模版

var data = `<html></html>` //可替换为已获取的html
OpenWindow = window.open("", "_blank");
OpenWindow.document.write(data)
OpenWindow.document.close()
// 为避免弹出新窗口被拦截可修改为
OpenWindow = window.open("_blank");
var data = "<html><head><script>function redirect(){document.form1.submit();}</script></head><body onload='redirect();'><form name='form1' method='post'  action='https://www.csdn.net' ><input type='hidden' name='customername' value='test'></form></body></html>"
OpenWindow.document.write(data)
OpenWindow.document.close()
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值