如何让 JavaScript 制作(产生)新页面?

发布于 2024-08-17 04:23:04 字数 138 浏览 2 评论 0原文

我想在页面上制作一个按钮,可以在同一页面中调用JS函数。该函数需要创建(打开)新窗口,其 HTML 代码是从 JS 函数本身给出的。我怎样才能做到这一点?

这样做的目的是从特定页面生成适合打印的页面。

请注意:不能使用 AJAX。

I would like to make a button on a page that can call a JS function in the same page. The function will need to create (open) new window which its HTML code was given from the JS function itself. How can I do that?

The purpose of this is to produce a print friendly page out of a specific page.

Please notice: No AJAX can be used.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

陪你搞怪i 2024-08-24 04:23:04
var opened = window.open("");
opened.document.write("<html><head><title>MyTitle</title></head><body>test</body></html>");
var opened = window.open("");
opened.document.write("<html><head><title>MyTitle</title></head><body>test</body></html>");
鸵鸟症 2024-08-24 04:23:04
var w = window.open("");
w.document.writeln("<the html you wanted to write>")
var w = window.open("");
w.document.writeln("<the html you wanted to write>")
浅唱ヾ落雨殇 2024-08-24 04:23:04
function fu() {
  var opened = window.open("");
  opened.document.write("Your HTML here");
}
function fu() {
  var opened = window.open("");
  opened.document.write("Your HTML here");
}
你与清晨阳光 2024-08-24 04:23:04
<textarea id="code" placeholder="Put code here!" width="500" height="500">
<DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html></textarea>
<input id="width" placeholder="width">
<input id = "height" placeholder="height">
<button onClick="open();">Open the window!</button>
<button onClick="write();">Apply the html to the window</button>
<button onClick = "resize();">Resize the window!</button>
<script>
var win;
function open(){
win = window.open("", "", "");
win.resizeTo(screen.width, screen.height);
}
function resize(){
win.resizeTo(eval(document.getElementById("width")), eval(document.getElementById("height")))
}
function write(){
win.document.write(document.getElementByid("code").value);
}
</script>

在这里您可以输入内容并更改窗口。希望您喜欢! :)

<textarea id="code" placeholder="Put code here!" width="500" height="500">
<DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html></textarea>
<input id="width" placeholder="width">
<input id = "height" placeholder="height">
<button onClick="open();">Open the window!</button>
<button onClick="write();">Apply the html to the window</button>
<button onClick = "resize();">Resize the window!</button>
<script>
var win;
function open(){
win = window.open("", "", "");
win.resizeTo(screen.width, screen.height);
}
function resize(){
win.resizeTo(eval(document.getElementById("width")), eval(document.getElementById("height")))
}
function write(){
win.document.write(document.getElementByid("code").value);
}
</script>

Here you can input things and change the window. Hope you enjoy! :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文