【发布时间】:2019-05-12 03:55:02
【问题描述】:
假设我有一些使用相对路径的预定义资产的 HTML,我将如何在当前页面中加载该 HTML 并同时将窗口位置更改为正确的 URL,以便页面及其所有资产正确加载。
目前如果我使用:
const w = window.open()
w.document.write("<html><body><p>help</p></body></html>")
w.location.replace("http://baseUrl.com")
页面然后呈现 html,然后在替换位置时重新加载,使 document.write 无用。
有没有一种方法可以同时进行,以便 url 和 html 一样加载?
如果我这样做了
const w = window.open()
w.location.replace("http://baseUrl.com")
w.document.write("<html><body><p>help</p></body></html>")
第三行没有运行,因为在替换位置时我无法访问 w 变量。
任何帮助将不胜感激。提前致谢。
【问题讨论】:
标签: javascript html url query-string webpage