iframe分线是双后退按钮

iframe breakout is double back button

本文关键字:按钮 iframe      更新时间:2023-09-26

我正在使用从书签调用的iframe,它调用一个html页面,该页面显示用户正在查看的页面的详细信息。要关闭我正在使用的 iframe:

<a href="<? echo $original_page_url; ?>" target="_parent">X Close Window</a>

这将关闭 iframe 并使用户停留在他们所在的同一页面上。然而,这是理想的,就浏览器而言,他们必须按两次后退按钮才能回到之前的位置,例如一些搜索结果,因为他们基本上已经连续两次访问当前页面。一次是原来的,然后当我关闭 iframe 时再次出现。

有没有更好的方法来避免这种情况?

这是生成 iframe 的书签代码:

javascript:(function%20(d)%20{var%20modal%20=%20document.createElement('iframe');
modal.setAttribute('src',%20'http://blah.com/info.html?url='+encodeURIComponent(window.location.href)+'&page_title='+document.title);
modal.setAttribute('scrolling',%20'no');modal.className%20=%20'modal';
document.body.appendChild(modal);var%20c%20=%20document.createElement('link');
c.type%20=%20'text/css';c.rel%20=%20'stylesheet';
c.href%20=%20'//blah.com/css/iframe.css';
document.body.appendChild(c);}(document));

使用以下 JavaScript 代码:

document.getElementById('iframeId').style.display='none';

此外,您可以在 iframe 中关闭此 iframe:

parent.document.getElementById('iframeId').style.display='none';

这将从父级获取 iframe 对象,并将其可见性设置为隐藏。

尝试window.location.replace

也许像这样

<a onclick="window.location.replace('<? echo $original_page_url; ?>')">X Close Window</a>