Click to See Complete Forum and Search --> : Problems with calling javascript commands from an external window...


eddie_ch
06-20-2003, 09:43 AM
I'm currently working on a community forum and I'm having problems with detecting a frame page from an external "popup" window.

The main frame contains 3 frames named: "sidebar", "messagelayout", and "postbox", whereas for the main frame itself, i've named it "msgframe<?= $currentboard ?>" with the following script:

<SCRIPT LANGUAGE="JavaScript">
window.name = 'msgframe<?= $currentboard ?>';
</SCRIPT>

ps. "<?= $currentboard ?>" is the frame's ID number generated from php scripts...

so far there's no problem with detecting the window.name for the users since I've set a detect window.name function button for them to try out and it's all working fine!

now what i'd like to do is from an external window: e.g. a popup window, send javascript commands into an object within the main frame's postbox, and after performing these functions, the popup window would close itself. Using a focus() command as an example, to do that I've set the following in the popup window's page:

within the <head> area:

<head>
<script language="Javascript">
var msgframe = window.open("", "msgframe<?= $currentboard ?>")
</script>
</head>

within the <body> area:

<a href="javascript:void(0)" onclick="
javascript:msgframe.focus();
msgframe.postbox.msgform.msgbody.focus();
window.close();">A button</a>

p.s. msgframe.focus() sets the frame window in focus first, msgframe.postbox.msgform.msgbody is the targeted object within postbox to be focused at, and after these 2 commands, the popup window would close itself.

I just like to know if there's any problems with the script, and if there's any more safer and guaranteering ways to achieve the same effect? because so far it works fine only for half the users and myself, other users can't even run the msgframe.focus(), msgframe.postbox.msgform.msgbody.focus() commands to start off with nor does the popup window close itself... some of them even get error messages saying that the commands cannot be executed... I wonder if that has anything to do with setting the msgframe variable in the <head> area...

my IE version is 6.0.2800.1106IS and it works fine.
one of the users' IE version is 6.0.2600.0000.xpclnt_qfe.021108-2107 and this doesn't work! it prompts error messages when the scripts in the popup window are runned... (and this is a chinese version of internet explorer)
we've compared our Internet Options/Advanced settings and everything's the same!

Would really appreciate if anyone can help :)

SlankenOgen
06-20-2003, 10:09 AM
javascript all one word Not: java script.

Try this

<a href="#" onclick="msgframe.focus() && msgframe.postbox.msgform.msgbody.focus() &&
window.close();">A button</a>

or

<a href="#" onclick="msgframe.focus(); msgframe.postbox.msgform.msgbody.focus();
window.close();">A button</a>

~mgb

eddie_ch
06-20-2003, 10:16 AM
Originally posted by SlankenOgen
javascript all one word Not: java script.

Try this

<a href="#" onclick="msgframe.focus() && msgframe.postbox.msgform.msgbody.focus() &&
window.close();">A button</a>

or

<a href="#" onclick="msgframe.focus(); msgframe.postbox.msgform.msgbody.focus();
window.close();">A button</a>

~mgb

thanx! yes i know but when I copied and pasted my messages here all the javascript word has a space appearing between them after being submitted...

as for the
<a href="#" onclick="msgframe.focus(); msgframe.postbox.msgform.msgbody.focus();
window.close();">A button</a>
method, that's just the same with what i've already have, I don't think the && method would make much of a difference and that's not where the problem is occuring... thanx anyway :)

Khalid Ali
06-20-2003, 12:06 PM
Your question is somewhat confusing,I think you are trying to find out how to communicate between parent and child windows. if thats the case try this link

http://68.145.35.86/skills/javascripts/ParentWinInteractionWithChildWin.html

Since you mentioned that you have frames in the parent window,you will need to change the code in the child window like this for example this line from a child window

var disFld_String =eval('top.opener.document.getElementById(frmName).'+fldName);

will be changed like this assuming there is a frame thats name is "rightFrame"

var disFld_String =eval('top.opener.rightFrame.document.getElementById(frmName).'+fldName);

eddie_ch
06-20-2003, 12:16 PM
Originally posted by Khalid Ali
Your question is somewhat confusing,I think you are trying to find out how to communicate between parent and child windows. if thats the case try this link

http://68.145.35.86/skills/javascripts/ParentWinInteractionWithChildWin.html

Since you mentioned that you have frames in the parent window,you will need to change the code in the child window like this for example this line from a child window

var disFld_String =eval('top.opener.document.getElementById(frmName).'+fldName);

will be changed like this assuming there is a frame thats name is "rightFrame"

var disFld_String =eval('top.opener.rightFrame.document.getElementById(frmName).'+fldName);

yes thanks alot! I've been trying to look for alternative ways to "communicate" between parent and child windows cos i think the current method i've been using is somewhat unstable, at least it doesn't work with all IE browsers.. thanks ALOT! :)

Khalid Ali
06-20-2003, 12:20 PM
You are welcome...glad to be of any help..:D :D