Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

JavaScript problem with popup refering to parent window



Hi,

i'm hoping to get some help with a javascript problem i am encountering with safari 1.3. the same javascript works fine in firefox and IE, but i must also support safari users. i'll describe a test case to demonstrates the problem. the pertinent code is included below.

test case:
===
basically, a web page contains a link that, when clicked, causes a popup window to appear. in the popup there is a link that, when clicked, should cause an input field from a form back in the main page (parent window) to be filled in with some text.


in the code below, the alert() messages i get in the popup function changeListing() are:
* '[object Window]' for parent
* 'undefined' for parent.creator
* 'undefined' for parent.paramname


with parent.creator undefined i can't get to the main pages changeText() function, which would write the text to the form's input field.
===



if someone could point me in the right direction to solve this problem i would be very grateful.


--
Richard Hale


=============================================================

POPUP WINDOW:

<html><head><title>popup</title>
<script language="JavaScript">
<!--
function changeListing(pvalue) {
    alert("changeListing(): parent: "+parent+"\n");
    alert("changeListing(): parent.creator: "+parent.creator+"\n");
    alert("changeListing(): parent.paramname: "+parent.paramname+"\n");
    parent.creator.changeText(parent.paramname, pvalue);
    parent.close();
}
// -->
</script>
</head><body>
<a HREF="javascript:changeListing('TEST VALUE');">TEST VALUE</a>
</body>
</html>

=============================================================

MAIN PAGE:

<html><head><title>jstest page</title>
<script language="JavaScript">
<!--
// *********************************************************************
function openNewWin(pname) {
  win = open('jstestpopup.html', '', 'scrollbars=no,width=250,height=25');
  win.creator = self;
  win.paramname = pname;
  win.focus();
}
// *********************************************************************
function changeText(pname, pvalue) {
  index = getIndex(pname);
  document.modform.elements[index].value = pvalue;
}
// *********************************************************************
function getIndex(pname) {
  n_elements = document.modform.elements.length;
  for (var i=0; i<n_elements; i++) {
    if (document.modform.elements[i].name==pname) { return i; }
  }
  return -1;
}
// *********************************************************************
// -->
</script>
</head><body>
<form name="modform" method="post" action=".">
  <div align="center">
    <a HREF="javascript:openNewWin('jstest')">open popup</a>
    <br><br>
    value: <input type="text" name="jstest" size="10">
  </div>
</form>

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Web-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/web-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.