IFrame content swapping bug?

2019-05-04 09:51发布

问题:

I have a web page with a number of iframes, including 3rd party iframes like ad sense and various sharing buttons.

In Firefox, I've noticed that occasionally the content of these iframes get swapped, such that you'll get an ad sense ad where another iframe is. It seems completely random where iframe content shows up. It seems it may have something to do with caching.

Does anyone know what causes this, or any steps I can take to prevent this from happening?

回答1:

In case anyone is looking I was able to track down the bug report:

https://bugzilla.mozilla.org/show_bug.cgi?id=356558

It's been 4 years and it doesn't even look like they have confirmed it.



回答2:

The workaround described in that Mozilla bug report worked for me:

<iframe src="webpage2.html?var=xxx" id="theframe"></iframe>

<script>
var _theframe = document.getElementById("theframe");
_theframe.contentWindow.location.href = _theframe.src;
</script>


回答3:

One plausible answer is that two iframes have the same name. I've experienced this several times in conkeror (firefox based), and every time it's been a name conflict.



回答4:

I've been wrestling with this for awhile now. The problem is with firefox and the way that it caches iframe content. It's not random either. There is nothing to do to prevent this short of not using iframes.

You can reload the iframes onload using something like:

var reloadIframes = function () {
    var a = window.frames, b = a.length
    while (b--) {
        a[b].src = a[b].src;
    }
}

In the case of ads it will cause double impressions which will violate you contract.

An easy way to replicate the issue is create 3 html files.

<!--frame1.html-->
<html>
<body>
<h3>frame one</h3>
</body>
</html>

<!--frame2.html-->
<html>
<body>
<h3>frame two</h3>
</body>
</html>

<!--index.html-->
<html>
<body>
<iframe src="frame1.html"></iframe>
<iframe src="frame2.html"></iframe>
</body>
</html>

Open in firefox. Then switch frame one and frame two.

<!--index.html-->
<html>
<body>
<iframe src="frame2.html"></iframe>
<iframe src="frame1.html"></iframe>
</body>
</html>

Refresh index.html. The iframes will not be swapped until you clear your cache.

There is a bug in at mozilla but no one is currently working on it.



回答5:

This problem maybe similar to yours

try to put

window.onload = yourcode; 

together with body unload.

i have the tool tip javascript on head segment which contain

window.onload = initTip;

but conflict with my onload iframe

<body onload = "parent.myframe.location='mypage.html'">

my solution : delete that window.onload = initTip; from head segment, then put them into body.

<body onload = "initTip(); parent.myframe.location='mypage.html'">

it's work with reload button on firefox