Javascript 在window.open中使用相对URL
我使用下面的JS代码通过填充动态生成的代码来打开新窗口Javascript 在window.open中使用相对URL,javascript,jquery,html,Javascript,Jquery,Html,我使用下面的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 th
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
,不起作用
<tr><td colspan='2' align='center'><img id='imglegend' src='/images/Legend.jpg'></td></tr>
编辑:
我使用javascript动态填充内容,只需在浏览器窗口中提供一个有效的url,即可使我的超链接和图像源引用正常工作
另外,js代码中指出的页面没有物理存在。如何将url分配给新打开的窗口
您需要传递和URL到window.open()
或者
或者,
你甚至可以说
w.location.assign("http://www.mozilla.org");
参考通常,您会打开一个窗口,给出函数中的所有参数,如:
window.open('yoururl','title','some additional parameters');
但是你可以像以前那样做,但是你使用了错误的变量来添加你的url。它应该是
w.document.location.href
:
var w = window.open();
w.document.title = "New window";
w.document.location.href = "hello.com"; //how to assign the url to the newly opened window
$(w.document.body).html(stored);
return false;
谢谢,但在我的情况下,完整的url是未知的,我能给出相对路径吗?
w.document.location.href=“hello.com”代码>将把打开的页面重定向到hello.com.Yes。这就是OP想要的。@putvande不,我不想要那个。我使用javascript动态填充内容,只需要浏览器窗口中的一个有效url,就可以使我的超链接和图像源引用正常工作。没有OP希望使用指定的url打开窗口。如果我做得对,你能检查我的更新代码吗?
window.open('yoururl','title','some additional parameters');
var w = window.open();
w.document.title = "New window";
w.document.location.href = "hello.com"; //how to assign the url to the newly opened window
$(w.document.body).html(stored);
return false;