[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Javascript questions



I'm following up to my own response here. I tried doing what I suggested and I had it 
almost right.  The following HTML file presents two buttons ("open" and "close") The "open" 
button, when clicked, opens a new winodw (w2) and writes HTML lines to it. The HTML which 
is written to w2 simply creates a button ("ok") in the new window which, when pressed, will 
call the main window's validate() function, passing it's own windowId.  The validate 
funtion will then close the calling window and pop up an alert indicating that it was 
called.

I had a problem when I first tried this. Originally I was trying to write a JavaScript into 
the new window. I had the following lines in the initWindow() function:

  windowId.document.write('<SCRIPT>');
   .
   .  (some JavaScript written here)
   .
  windowId.document.write('</SCRIPT>');

but I got errors when the '</SCRIPT>' line was encountered. I think that Netscape was 
interpreting the </SCRIPT> in the write call as the end of the current script (instead of 
just passing it into the write call), which is NOT what I intended.

 I think this is what you were interested in. If not let me know.

-------------- EXAMPLE --------------
<html>
<head>
<script language = "javascript">

function newWindow(windowName)
{
  w2 = window.open(windowName);
  initWindow(w2);
  return w2;
}

function initWindow(windowId)
{
     windowId.document.open();
     windowId.document.write('<HTML>');
     windowId.document.write('<HEAD>');
     windowId.document.write('</HEAD>');
     windowId.document.write('<BODY>');
     windowId.document.write('<FORM name = "controlPanel">');
     windowId.document.write('<INPUT type =  "button" name = "okButton" value = "OK" 
onClick = "mainWindow.validate(window)">');
     windowId.document.write('</FORM>');
     windowId.document.write('</BODY>');
     windowId.document.write('</HTML>');
     windowId.document.close();
     windowId.mainWindow = window;
}


function validate(windowId)
{
   windowId.close();
   window.alert("Validate function called");
}

</script>
</head>
<body>
<form name="controlPanel">
<input type = "button" name = "open"     value = "Open"     onClick = "w2 = 
newWindow('w2')">
<input type = "button" name = "close"    value = "Close"    onClick = "w2.close()">
</body>
</html>
------------ END EXAMPLE ------------ 

-- Robert
____________________________________________________

Robert Thuleen
Sr. Software Engineer
Science Applications International Corp (SAIC)
San Diego, Ca

mailto:thuleen@mls.saic.com
http://www.saic.com
http://www.free.cts.com/crash/t/thuleen