Javascript 如何打开新的浏览器窗口预览html
我正在研究html和jquery。我正试图用我的html代码打开一个新的浏览器窗口。我得到了一些关于DOM窗口打开方法的信息,但该方法总是打开一个新选项卡,但我想打开一个新的不同窗口。请任何人帮助我以下是W3学校的例子供参考Javascript 如何打开新的浏览器窗口预览html,javascript,jquery,html,Javascript,Jquery,Html,我正在研究html和jquery。我正试图用我的html代码打开一个新的浏览器窗口。我得到了一些关于DOM窗口打开方法的信息,但该方法总是打开一个新选项卡,但我想打开一个新的不同窗口。请任何人帮助我以下是W3学校的例子供参考 function myFunction() { var w = window.open(); w.document.open(); w.document.write("<h1>Hello World!</h1>");
function myFunction() {
var w = window.open();
w.document.open();
w.document.write("<h1>Hello World!</h1>");
w.document.close();
}
函数myFunction(){
var w=window.open();
w、 document.open();
w、 写下“你好,世界!”;
w、 document.close();
}
试试这段代码
<script>
function nWin() {
var w = window.open();
var html = $("#toNewWindow").html();
$(w.document.body).html(html);
}
$(function() {
$("a#print").click(nWin);
});
</script>
<div id="toNewWindow">
<p>Your content here</p>
</div>
<a href="javascript:;" id="print">Open Window</a>
函数nWin(){
var w=window.open();
var html=$(“#tonewindow”).html();
$(w.document.body).html(html);
}
$(函数(){
$(“打印”)。单击(nWin);
});
你的内容在这里
您可以使用下面的代码打开新窗口
<!DOCTYPE html>
<html>
<body>
<p>Click the button to open a new window called "MsgWindow" with some text.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var myWindow = window.open("", "MsgWindow", "width=200,height=100");
myWindow.document.write("<p>This is 'MsgWindow'. I am 200px wide and 100px tall!</p>");
}
</script>
</body>
</html>
单击按钮打开一个名为“MsgWindow”的新窗口,其中包含一些文本
试试看
函数myFunction(){
var myWindow=window.open(“,”MsgWindow“,”宽度=200,高度=100”);
myWindow.document.write(“这是‘MsgWindow’。我宽200像素,高100像素!”;
}
在打开功能中提供高度、宽度参数。试着这样做:window.open('http://www.google.com/“,”asdas“,”工具栏=0,宽度=400,高度=320,左侧=200,顶部=200,滚动条=1,可调整大小=1’
尝试使用高度
和宽度
创建新窗口strWindowFeatures
类似于w=window.open(url,'name','height=200,width=150')代码>非常感谢,工作正常:)我们可以在新窗口上滚动吗?是的,您只需在宽度和高度参数之前添加“滚动条=1,宽度=200,高度=200”