How To Prevent Iframe Pages Being Inserted Into IE Browsing History

左心房为你撑大大i 提交于 2019-12-21 20:46:50

问题


I'm having a lot of trouble with iframe pages being inserted into the browsing history of IE9. It's a pain because you have to click back several times in order to get to the previous page. What is the cause of this? Is it a bug in the browser or the page?

Edit: I realized I was using javascript to update the source of all iframes on the page to add the wmode=transparent attribute.

$('iframe').each(function () {
    var url = $(this).attr("src")
    $(this).attr("src", url + "?wmode=transparent");
 });

This was added to combat menu navigations were going behind YouTube videos. Is there a way to prevent IE from inserting these events into the history?


回答1:


An option would be to replace the iframe rather than update the source.

$('iframe').each(function () {
   var url = $(this).attr("src")
   //$(this).attr("src", url + "?wmode=transparent");

   url = url + "?wmode=transparent";

   var frm = document.createElement("iframe");
   frm.src = url;
   //copy attributes of this -> frm
   $(this).replaceWith(frm);
});

A history entry is made any time an iframe's src attribute is modified after it has been inserted into the DOM. If you aren't in control of the contents of the iframe (a third party iframe), then if they modify the location of their page in any way a history entry will be created.




回答2:


I don't know about all circustances but at finance.yahoo.com a link to facebook's like.ph is sometimes inserted in the back button history. It is caused by a script on the page. It happens when the facebook link becomes visible on the web page. That triggers the function that creates the link in the back button history. The user does not have to click on anything to cause this to happen.




回答3:


instead of

$(this).attr("src", url + "?wmode=transparent");

do

$(this).get(0).contentWindow.location.replace(url + "wmode=transparent");


来源:https://stackoverflow.com/questions/9945587/how-to-prevent-iframe-pages-being-inserted-into-ie-browsing-history

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!