Reading content of a HTML that I've open in a subwindow...

H

Hugo

Hi all,

Well I don't know if it's possible, but I would like to able to read
the content of a html file that I've opened in a new window, but do
this from the parent html file.
I think that maybe this isn't at all possible. But if anybody as an
idea it would be great.

The code is bellow
thx
Hugo


Parent page:
------------
<html>
<head>
<title>Test</title>
<script language="JavaScript1.2" type="text/javascript">
<!--
var myWindow;
function detect(){
myWindow = window.open("http://localhost/webapp1/status.html",
"Status");
alert(myWindow.document.forms[0].hidden_status);
myWindow.document.close() ;
}
//-->
</script>
</head>
<body>
<form>
<input type="button" VALUE=" Test Server" ONCLICK="detect();">
</form>
</body>
</html>

Child file:
----------
<html>
<head>
<title>Server</title>
</head>
<body>
<form name="my_form">
<input type="hidden" name="hidden_status" value="on"/>
</form>
</body>
</html>
 
L

Lasse Reichstein Nielsen

Hi all,

Well I don't know if it's possible, but I would like to able to read
the content of a html file that I've opened in a new window, but do
this from the parent html file.
I think that maybe this isn't at all possible. But if anybody as an
idea it would be great.

It is not possible if the page is from another domain. The standard
security measures prevents scripts from gaining cross-domain
information.

If the page is from the same domain, you can access it as you do the
current page, only writing "myWindow.document" instead of just
"document".
function detect(){
myWindow = window.open("http://localhost/webapp1/status.html",
"Status");
alert(myWindow.document.forms[0].hidden_status);

Here you might be a little too fast. The contents of the window
is loaded asynchroneously, so it is probably not loaded yet when
the alert statment is executed.

You can either delay the alert
setTimeout(function(){
alert(myWindow.document.forms[0].hidden_status);},
1000);
(or however long you expect it to take ... the safest bet would be to check
if the page has loaded and reschedule the alert for later if it hasn't).
myWindow.document.close() ;

You probably mean
myWindow.close()
to close the window.

/L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top