How To Prevent Iframe Pages Being Inserted Into IE

2020-07-23 04:37发布

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?

3条回答
戒情不戒烟
2楼-- · 2020-07-23 05:00

instead of

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

do

$(this).get(0).contentWindow.location.replace(url + "wmode=transparent");
查看更多
放我归山
3楼-- · 2020-07-23 05:05

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.

查看更多
劫难
4楼-- · 2020-07-23 05:20

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.

查看更多
登录 后发表回答