【问题标题】:When opening iframe content in a new tab, make it open in an iframe that sits inside a page在新选项卡中打开 iframe 内容时,使其在页面内的 iframe 中打开
【发布时间】:2019-03-11 08:49:29
【问题描述】:

我在 iframe 中打开了各种页面。我想避免这样的情况,即如果用户在新选项卡中打开其中一个页面,它本身会作为页面打开。相反,我希望父页面在新选项卡中打开,并嵌入 iframe 内容。

我有一些来自我构建的旧网站的 javascript,在使用框架执行此操作时可以完美运行。我没有编写脚本,并且有点不确定如何更新它。该脚本进入父框架:

var fname="mainFrame";

window.onload=function(){
var d=document.location.search;
if(d!='')self.frames[fname].document.location.href=d.substring(d.lastIndexOf('?')+1,d.length);
}

这在子框架中:

if(self.location==top.location)self.location="index.htm?article.htm";

如何修改此脚本以使用 iframe?鉴于我已经使用该脚本十多年了,它仍然是最好或最有效的方法吗?我正在使用 Bootstrap,所以如果它比上述 javascript 方法更好,请不要介意 jQuery 解决方案。

【问题讨论】:

    标签: javascript jquery iframe


    【解决方案1】:

    知道了!

    window.onload=function(){
        var ifrm = document.getElementById('newsframe');
        var d=document.location.search;
        if(d!='')ifrm.src=d.substring(d.lastIndexOf('?')+1,d.length);
    }

    【讨论】:

      猜你喜欢
      • 2016-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-30
      • 1970-01-01
      相关资源
      最近更新 更多