加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

javascript – 使用window.open的相对网址

发布时间:2020-12-14 23:08:08 所属栏目:资源 来源:网络整理
导读:我在JS代码下面使用通过填充动态生成的代码来打开新窗口. function OpenWindow(obj) { var w = window.open(); var stored = $(obj).parent().find("div").html(); w.document.title = "New Window"; w.document.URL = "hello.com/dummypage.html"; //how to

我在JS代码下面使用通过填充动态生成的代码来打开新窗口.

function OpenWindow(obj) {
    var w = window.open();
    var stored = $(obj).parent().find("div").html();
    w.document.title = "New Window";
    w.document.URL = "hello.com/dummypage.html"; //how to assign the url to the newly opened window
    $(w.document.body).html(stored);
    return false;
}

本文档中使用的相对URL表示对于img src,在本文档中不起作用.

编辑:

我使用javascript动态填充内容,只需要在浏览器窗口中有一个有效的URL,以使我的超链接&图像源参考工作.

附:在js代码中指出的页面没有物理存在.

最佳答案
如何将URL分配给新打开的窗口

你需要传递和URL到window.open()

window.open('http://www.google.com');//will open www.google.com in new window.
window.open('/relative_url'); //opens relatively(relative to current URL) specified URL

要么,

function OpenWindow(obj) {
    var w = window.open();
    w.location = "hello.com/dummypage.html"; //how to assign the url to the newly opened window
}

要么,
你甚至可以说,

w.location.assign("http://www.mozilla.org");

参见Window.location

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读