请教各位大佬,小弟感激不尽!!JS中 document.write('中相对路径失效

congmaxz 2020-10-24 06:52:56
index.html为:
<script>
window.onload = function () {
function open1() {
window.open('javascript:document.write("<iframe src=d:/web/test.html(显示)/test.html(不显示) height=850 width=662></iframe>");document.close()', null, 'height=850,width=505,top=20,left=100, _blank, toolbar=no,menubar=no,location=no,status=no');
};
oBtn = document.querySelector('#open-btn01');
oBtn['onclick'] = function () {
open1();
};
};
</script>
<a href="" id="open-btn01" style="color:#000000;">test</a>

test.html为任意内容,比如<p>hello</p>也不显示。
以上HTML和test.html在同一目录(web)中。
请教各位大佬,小弟感激不尽!!
...全文
7803 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
congmaxz 2020-10-27
  • 打赏
  • 举报
回复
已找到原因了!谢谢各位! 需要js中加上var path = location.origin + location.pathname.replace(/[^\/]*$/,""); iframe前加上<base href='+ path +'/>
Mr.Ma98 2020-10-27
  • 打赏
  • 举报
回复
你看看你文件的位置需不需要向上找
葉幺 2020-10-26
  • 打赏
  • 举报
回复
如果同目录的话就写成 test.html或者 ./test.html(./为当前目录) /test.html(/为根目录)
qybao 2020-10-25
  • 打赏
  • 举报
回复
改成以下试试 src=“./test.html” 或者 src=“http://your_domain/test.html”
我头发比你多 2020-10-24
  • 打赏
  • 举报
回复
写个相对根目录的路径

87,922

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧