Link to home
Start Free TrialLog in
Avatar of simsingh
simsingh

asked on

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?
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

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.


Avatar of smaccari
smaccari

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>
Avatar of simsingh

ASKER

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

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



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

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


ASKER CERTIFIED SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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>