将相对网址与 window.open 一起使用
Using relative urls with window.open
我正在使用下面的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
,在本文档中不起作用。
<tr><td colspan='2' align='center'><img id='imglegend' src='/images/Legend.jpg'></td></tr>
编辑:
我使用 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.open('yoururl','title','some additional parameters');
但是你可以像你所做的那样做,但你使用了错误的变量来添加你的网址。应该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;
相关文章:
- 直接下载文件,而不是从window.open(url)
- document.open/document.write没有正确地清除chrome中的文档——这是chrome的错误吗
- 转义符不能与innerHTML一起使用
- 如何将PDF作为二进制文件传递到window.open()
- 高亮显示与数组字符串一起使用时文本插件中断
- setTimeout可以与闭包内的函数一起使用吗
- 将依赖外部库的UMD模块与browserfy捆绑在一起
- 为什么window.open不打开一个以变量形式给出的链接
- Highcharts colorsByPoint与系列中的线性渐变一起使用时不起作用
- 如何将js库与typescript一起使用
- 将webpack和babel与父项目目录中的文件一起使用
- 将 Drag&Drop 与 jsTree 和 DataTables 一起使用
- Javascript-如何让脚本与Ajax请求的数据一起运行
- 将两个ext.TabPanels滚动到一起
- 将jQuery UI Timepicker Addon与React一起使用
- 将相对网址与 window.open 一起使用
- Window.open () and target="_blank"不能在IE中一起工作
- target和window open在IE中不能一起工作
- Jquery包装方法无法与window.open一起使用
- 窗口.与参数一起使用时,Open不打开新窗口