Javascript 如何在 document.location.href 中添加 target= "_parent"


document.location.href="http://verttgrettest.com/testpaper.aspx?VideoId=1"

Javascript 如何在 document.location.href 中添加 target="_parent"

你不能

.href实际上只是您要重定向到的URL。您必须直接更改要定位的框架的.href,而不是您所在的窗口/框架的 href,例如

parent.document.location.href = 'http://...'
window.open(
  'http://verttgrettest.com/testpaper.aspx?VideoId=1',
  '_blank' 
);

//但弹出窗口阻止程序可能会阻止它

window.open('http://verttgrettest.com/testpaper.aspx?视频 ID = 1')

我使用以下代码:

if (parent)
    parent.document.location.href = '/iframe_parent';
else
    location.href = '/no_iframe';

最新更新