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()