onblur, onfocus not working iframe mozilla

I have the following code in my page:

  <iframe id="the_editor_x5" onblur="TestMe();" onfocus="loadAlert();" name="the_editor_x5" width="99%" height="99%" style="Background:white;"></iframe>


<textarea id="the_editorHtmlBox" runat="server" name="the_editorHtmlBox" class="" style="width:99%;font-size:10pt;font-family: Courier New, Courier;display:none" onchange="RTB_fromHTMLView('the_editor')"></textarea>
                        
<input id="the_editor" runat="server" enableviewstate="true" name="the_editor" type="hidden" value="&lt;p>&amp;nbsp;&lt;/p>" />

---------------

TestMe and loadAlert are two functions that simply call alerts. In IE, the alerts show up when I give focus to the iframe and take focus away. In Mozilla, the events never fire. Also, if I set the iframe's document.designMode etc to on, the events still don't fire in mozilla.

Does anyone have an idea as to why?
simsinghAsked:
Who is Participating?
 
ZvonkoSystems architectCommented:
Yes, it is different.
And it does partialy make sense to me.
In IE you can assigne handlers for the emebeded window CONTENT.
In FF are this basic assignments overwritten by the real window empty handlers.
On reload or refresh does the FF has an side effect not to reload the window completely. Therefore are the handlers from parent window used as loaded handlers.

I mean this: in an iframe you have always problems with the events which function are located in parent window context. The event is fired in iframe window and the function is not defined in that iframe window context. You see?

The event handler defined in the iframe tage are an exception to that dilema; they are always fired in the parent window context, and thats the way how IE handles the onfocus and onblur of the iframe, but it is not realy consistant to me.

0
 
ZvonkoSystems architectCommented:
Perhaps your loadAlert() does get a runtime error in Mozilla.
Do you use window.event reference in that functions?
window.event is not defined in Mozilla.


0
 
smaccariCommented:
Maybe you should try to assign the handlers to the window object of the iframe element by script:

<iframe id="the_editor_x5" name="the_editor_x5" width="99%" height="99%" style="Background:white;"></iframe>
<script>
document.getElementById("the_editor_x5").contentWindow.onfocus=loadAlert;
document.getElementById("the_editor_x5").contentWindow.onblur=TestMe;
</script>
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
simsinghAuthor Commented:
no the content window onfocus onblur doesnt' work. Not doing any window.event stuff....

ITs really really strange....
0
 
smaccariCommented:
Ok and what about this:

<iframe id="the_editor_x5" name="the_editor_x5" width="99%" height="99%" style="Background:white;"></iframe>
<script>
frames["the_editor_x5"].onfocus=loadAlert;
frames["the_editor_x5"].onblur=TestMe;
</script>

Doesn't it work at least in IE?
If it's working in IE and not FF, you should - as Zvenko supposed - look at your code in the handler.
window.event will not work with FF - nor Mozilla, nor Safari...
0
 
ZvonkoSystems architectCommented:
The events are realy not fired in Mozilla. Very strange.
0
 
smaccariCommented:
Mmm.. do not have FF here (am on my HTPC)..
Both frames and contentWindow failed to fire the event in FF?
0
 
ZvonkoSystems architectCommented:
OK, I have tested your both proposals.
Both proposals work in IE.
The folowing proposal does not work at all in FF:
<script>
frames["the_editor_x5"].onfocus=loadAlert;
frames["the_editor_x5"].onblur=TestMe;
</script>

But the first one:
<script>
document.getElementById("the_editor_x5").contentWindow.onfocus=loadAlert;
document.getElementById("the_editor_x5").contentWindow.onblur=TestMe;
</script>

has an absolutely strange behavior.
On load of that page does not hapen anything. I mean you load the page and focus the iframe and leave the iframe and nothing happens and no errors.
But after that when you refresh the page does the onfocus event fire. Becaise the event  handler calls an alert() does the iframe loose the focus but does not call the onblur handler. After clicking OK in the alert does the iframe fire again the onfocus handler, does alert and so on in an infinite loop. You need then the three fingers catch to kill the show by task manager.



0
 
ZvonkoSystems architectCommented:
OH, and it does not help to coment out the onfocus alert(); the onblur handler does not fire also without alert()

0
 
smaccariCommented:
So is this behaviour different from the one you'd get by writing this?

window.onfocus=loadAlert;
window.onblur=TestMe;

(am sorry again just trying to understand - as you do ;) -, but not having FF under the hand for testing)
0
 
simsinghAuthor Commented:
Yeah its freak'n weird. No onfocus or onblur evetns fire. THE reason is that onblur, I want to copy the contents of the document to a textarea (to have a WYSYWIG editor). That didn't work in mozilla but worked great in ie. Thus, the testing I am doing with alerts and stuff, but basically, no onblur, or onfocus evetns fire...


0
 
simsinghAuthor Commented:
okay, so while I don't have a solution, if you do "onsubmit" on the form itself, one can then achieve what i wanted to achieve.

So we don't need to worry about this anymore.

I will distribute points evenly between the contributors.
0
 
ZvonkoSystems architectCommented:
Hello simsingh,
the solution for your copy (when you have read my upper explanation) is to define the focus and blur handlers in the iframe page, not in the parent page. Iframe page can call parent functions by prefixing the parent. reference to the calls.
Like this:
<body onFocus="parent.loadAlert()" onBlur="parent.TestMe()">
<h1>Iframe</h1>
</body>

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.