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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.


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>
simsinghAuthor Commented:
no the content window onfocus onblur doesnt' work. Not doing any window.event stuff....

ITs really really strange....
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

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...
ZvonkoSystems architectCommented:
The events are realy not fired in Mozilla. Very strange.
smaccariCommented:
Mmm.. do not have FF here (am on my HTPC)..
Both frames and contentWindow failed to fire the event in FF?
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.



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

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)
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...


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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
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>

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.