I have some problems calling a specific iframe function after reloading another iframe. It works on all major browsers, but it behaves a bit strange on Microsoft Edge. To get the error you need the following constellation. All files are in the same directory on the same server. I have not set any content security policies.
If you upload the Frame1.html file, everything will be okay and you will get an alert message.
But if you click the "Click me" tag on the frame4.html file, the frame2.html file will reload and you will get a "permission denied" error because the parent object ( var tmpParent = parent; ) is unavailable. If you press a- again tag, it will work without errors.
I think this is an Edge error, because all other browsers can handle it, and this only happens on the first click.
An error also occurs if you use the top insted parent.
The code topFrame.js is used to find the topmost frame of my site. I can't just use the top because it should be possible to embed my site.
Does anyone have a key?
Thank you so much!
frame1.html
<!DOCTYPE html> <html> <head> <title>Frame 1</title> <script type="text/javascript"> var topFrame = this; function myAlert() { alert('alert'); } </script> </head> <body> <iframe id="overallContentWrapper" name="mainFrame" src="frame2.html" frameborder="0"></iframe> </body> </html>
Frame2.html
<!DOCTYPE html> <html> <head> <title>Frame 2</title> <script src="topFrame.js" type="text/javascript"></script> <script type="text/javascript"> window.addEventListener("load", function load(event) { window.removeEventListener("load", load, false); try { topFrame.myAlert(); } catch (e) { alert(e); } }, false); </script> </head> <body> <iframe name="subFrame" src="frame3.html" frameborder="0"></iframe> </body> </html>
Frame3.html
<!DOCTYPE html> <html> <head> <title>Frame 3</title> </head> <body> <iframe name="subsubFrame" src="frame4.html" frameborder="0"></iframe> </body> </html>
Frame4.html
<!DOCTYPE html> <html> <head> <title>Frame 4</title> </head> <body> <a href="frame2.html" target="mainFrame">Click me</a> </body> </html>
topFrame.js
try { var tmpParent = parent; var topFrame = tmpParent.topFrame; while (topFrame === undefined) { tmpParent = tmpParent.parent; topFrame = tmpParent.topFrame; } } catch (e) { alert(e); }
javascript microsoft-edge parent iframe
gollum1007
source share