I run the page:
<html> <head> <title>Frames</title> <link rel="shortcut icon" href=""> </head> <body> <p>Два фрейма</p> <iframe src="a.html" name="A"></iframe> <iframe src="b.html" name="B"></iframe> </body> </html> It has two frames, respectively.
Frame "A":
<html> <head> <title>A Frame</title> </head> <body> <p>Фрейм A</p> <a href='#1'>f2</a> <script> var f2 = parent.Bf; var aTag = document.getElementsByTagName('a'); aTag[0].addEventListener('click', f2, false); </script> </body> </html> and frame "B":
<html> <head> <title>B Frame</title> </head> <body> <p>Фрейм B</p> <a href='#2'>f</a> <p id='res'></p> <script> var x = 10; var y = 11; var xy = 0; var resHtml = document.getElementById('res'); function f(){ resHtml.innerHTML = xy; xy = x + y; x++; y++; return xy; } var aTag = document.getElementsByTagName('a'); aTag[0].addEventListener('click', f, false); </script> </body> </html> The idea is that when you click on a link located in frame "A",
<a href='#1'>f2</a> the click event should fire and start the function that is in frame "B". However, this event does not work every time. When reloading the page may or may not work.
The click event in frame "B" is stable.
Who faced a similar problem? Why event triggered "through time"?