Javascript 如何在 document.location.href 中添加 target="_parent"
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12875213/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Javascript how to add target="_parent" in document.location.href
提问by Ghostman
document.location.href="http://verttgrettest.com/testpaper.aspx?VideoId=1"
Javascript how to add target="_parent" in document.location.href
Javascript 如何在 document.location.href 中添加 target="_parent"
回答by Marc B
You can't, the .href
is literally just the URL you want to redirect to. You have to directly change the .href
of the frame you want to target, not the href of the window/frame you're in e.g.
您不能,.href
实际上只是您要重定向到的 URL。您必须直接更改.href
要定位的框架的 ,而不是您所在的窗口/框架的 href 例如
parent.document.location.href = 'http://...'
回答by Manjunath Manoharan
window.open(
'http://verttgrettest.com/testpaper.aspx?VideoId=1',
'_blank'
);
回答by Renon Stewart
//but popup blocker may block it
//但弹出窗口阻止程序可能会阻止它
window.open('http://verttgrettest.com/testpaper.aspx?VideoId=1')
window.open('http://verttgrettest.com/testpaper.aspx?VideoId=1')
回答by Tomex Ou
I use the following codes:
我使用以下代码:
if (parent)
parent.document.location.href = '/iframe_parent';
else
location.href = '/no_iframe';