首页 > 解决方案 > 使用javascript在另一个页面中打开一个html文件

问题描述

我想在javascript中使用打开一个新窗口。我已经使用 window.open() 函数完成了这项工作。如此处所见

   var opened = window.open("");
   opened.document.write("<p>helloWorld</p>"); 

我可以让函数打开一个 html 文件,而不是将我的 html 代码作为参数写在 opens.document.write() 函数中。

标签: javascripthtml

解决方案


如果 html 是静态的,您只需将其托管在您的网络服务器上的不同路径。

那么你只需要使用window.open("/path/to/html/file.html")

这是有关使用 window.open() https://developer.mozilla.org/en-US/docs/Web/API/Window/open的更多信息


推荐阅读