简体   繁体   中英

iframe unloaded immediately after loading

I have been using an iframe to embed content from a different site (on the same domain) into a web page. Up until now, my clients have been accessing the site using Internet Explorer 7 and everything has been working completely fine...they click a button, the iframe src property is updated and the content is loaded.

After some recent software changes, the clients are now required to access the web page in IE 8/9/10. When they click the button in any of these later version of IE however, the client page IS successfully loaded into the iframe, but only for a very brief period (less than half a second). Essentially the page is loaded but then immediately unloaded - I tested this was the case by displaying some alerts when the window load/unload events are fired.

I have tried and failed to find the cause of the problem using the browser debugging tools. I can't see any errors (or warnings for that matter) relating to the issue, and the rest of the site is functioning normally. I am aware that there have been several changes to the way iframes are handled in later browser versions, but I'm not sure whether this is the cause of the behaviour that I am observing. Is it possible that the newer browser versions are telling the iframe to unload? Does anyone have any ideas as to what might be causing this problem (am I even on the right tracks here)?

Any help would be greatly appreciated.

Just so that you are aware, this behaviour is reflected in both Chrome and Firefox (these are also going to be supported).

Edit:


For the sake of testing I have been injecting a very simple html file as the client page and I still experience the exact same problem:

<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript">     
        function clickFunction() {
            alert("Hello World!");
        }
    </script>
</head>
<body>
    <button id="myButton" onclick="clickFunction()">Click Me</button>
</body>
</html>

This html is injected into an iframe that is embedded on my web page. As far as I am aware there is nothing unusual about the iframe:

<iframe id='geode_iframe' style='width:100%;height:100%;left:0;top:0;position:fixed'></iframe>

When the button on my page is clicked, the following code is used to set the src of the iframe:

document.getElementById('geode_iframe').src='http://BI0002/IRSGeodeClient/Basic.html'

In theory this operation should be relatively straightforward, hence why I thought it more likely that I was unaware of some change in iframe behaviour.

I have managed to track down the cause of the problem at long last. The panel in which the iframe was embedded was actually being created twice, which I think was confusing the browser when I called document.getElementById (since I had two panels with the same id). I'm not sure exactly why this behaviour was occurring...perhaps IE7 and IE10 use a different post back model and I was getting an extra postback which was causing the creation code to execute again.

Thanks anyway.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM