By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,382 Members | 1,623 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,382 IT Pros & Developers. It's quick & easy.

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

P: n/a
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>
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hu*********@web.de (Hugo) writes:
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
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

P: n/a
DU
Hugo wrote:
Hi all,


DO NOT MULTI-POST in several newsgroups.

You posted the same question in netscape.devs-javascript

DU
---------------------------
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.