Click to See Complete Forum and Search --> : iframe onEvent problem
Hi,
i have a page with two iframes in it and i want to be able to tell which one the user last was typing in.
With ie 6 i just have a variable like iframeName = "frameOne"; to start with then in the iframe tag i have:
<iframe onfocus="changeFrameName('frameTwo')"....
where changeFrameName() changes the frameName variable.
This works well in IE 6, however doesn't work in NS7. There seems to be no onEvent actions for iframes in NS7.
So if any could give an answer that works in both ie6 and ns7, that would be cool.
Thanks.
Assuming the ID of your first IFrame is "iframe1" and the ID of your second IFrame is "iframe2," put this in the HEAD tag of the document containing the two IFrames:
<script type="text/javascript"><!--
var lastIFrameID = "";
--></script>
In your first IFrame (id="iframe1") put:
<input type="text" onFocus="parent.lastIFrameID='iframe1';">
In your second IFrame (id="iframe2") put:
<input type="text" onFocus="parent.lastIFrameID='iframe2';">
[J]ona
Thanks Jona for your reply, i'm not sure this solves my problem though.
the iframes will be used for editing with execCommand(), so they will actually be empty initially:
...
<iframe id="editpane" width="100%" height="397px" frameborder="0"></iframe>
...
so where would i stick:
<input type="text" onFocus="parent.lastIFrameID='iframe1';">
:confused:
I'm sorry, I was assuming you were using some sort of form object. Are you using Microsoft's contenteditable attribute?
[J]ona
no content editable is not used as it will not work in netscape 7
this is the bulk of it:
<script>
var rng;
var pane;
//turn design mode on, must use contentDocument etc for NS
function load(){
document.getElementById('titlepane').contentWindow.document.designMode = "on";
document.getElementById('editpane').contentWindow.document.designMode = "on";
document.getElementById('editpane').contentWindow.focus()
}
function changePane(paneName){
pane=paneName;
}
function getIFrameDocument(aID){
//if contentDocument exists, W3C compliant (Mozilla)
if (document.getElementById(aID).contentDocument){
return document.getElementById(aID).contentDocument;
} else {
//IE
return document.frames[aID].document;
}
}
//editing function, just passin what you want it to do
function cmdExec(cmd,opt) {
getIFrameDocument(pane).execCommand(cmd,"", opt);
document.getElementById(pane).contentWindow.focus()
}
...
which is called by:
...
<img class="image" src="images/bold.gif" alt="Bold" title="Bold" onClick="cmdExec('bold')">
...
then there is two iframes, one for the title and one for the body which you can edit. Much like the hotmail rich text editor.
Does execCommand() work for Netscape 7? I am not completely sure which engine NS7 uses, but if it is the Gecko 1.4 engine, it shouldn't have a problem with execCommand().
Do you have this online so that I may view it and further help you?
[J]ona
ummm its still in development, so no its not online at the moment. But i may be able to get it on the net shortly...
I could probably take a screen shot if that helps?
A screenshot would work, I suppose. You may also want to upload a .txt file with the HTML code, or a .zip file with all three files.
[J]ona
Hi,
I have it online now at:
http://www21.brinkster.com/adventureplaygr/Zodal/Online_Editor/openwin.htm
yeah need ns7 or ie 6 to view and it won't work properly at the moment. The two frames i was talking of were the title and body panes.
Thanks.:D