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

A little help with PHP and frames appreciated

P: 2
I am haveing problems trying to get access to another frame from a frame that runs php. The code is as follows essentially;

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>set</title>
</head>
<frameset rows="50%,50%">
<frame name="upper" src="upper.html">
<frame name="lower" src="http://localhost/test/lower.php">
</frameset>"
</html>

//upper.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>upper</title>
</head>
<body>
<P>upper</p>
</body>
</html>

//lower.php
<html>
<head>
<title>lower</title>
</head>
<body>
<?php
print("lower<br>\n");
print("<script language=\"JavaScript\">\n");
print("document.write(parent.frames.length);\n");
print("parent.frames[\"upper\"].document.open();\n");
print("parent.frames[\"upper\"].document.writeln(\"test2\");\n");
print("parent.frames[\"upper\"].document.close();\n");
print("</script>\n");
?>
</body>
</html>

Is there anyone that can tell me what I am doing wrong and if there is anything extra you have to do to be able to get a php file to access another frame under the same parent as this setup is getting denied access errors from the lower.php file part.
Jun 16 '06 #1
Share this Question
Share on Google+
3 Replies


Banfa
Expert Mod 5K+
P: 8,916
//lower.php
<html>
<head>
<title>lower</title>
</head>
<body>
<?php
print("lower<br>\n");
print("<script language=\"JavaScript\">\n");
print("document.write(parent.frames.length);\n");
print("parent.frames[\"upper\"].document.open();\n");
print("parent.frames[\"upper\"].document.writeln(\"test2\");\n");
print("parent.frames[\"upper\"].document.close();\n");
print("</script>\n");
?>
</body>
</html>
I don't think it's anything to do with php I don't think that you can re-open a document once it is loaded an write to it like that. You have to create a new document, also you are calling open with the wrong parameters.

try

[php]
<?php
print("lower<br>\n");
print("<script language=\"JavaScript\">\n");
print("document.write(parent.frames.length);\n");
print("var newDoc=parent.frames[\"upper\"].document.open(\"text/html\", \"replace\");\n");
print("newDoc.writeln(\"test2\");\n");
print("newDoc.document.close();\n");
print("</script>\n");
?>
[/php]

See http://www.w3schools.com/htmldom/met_doc_open.asp

and

http://www.w3schools.com/js/tryit.as..._document_open

oh and this is a whole lot easier to read as

[php]
<?php
print <<<JSWRITE
lower<br>
<script language="JavaScript">
document.write(parent.frames.length);
var newDoc=parent.frames["upper"].document.open("text/html", "replace");
newDoc.writeln("test2");
newDoc.document.close();
</script>
JSWRITE;
?>
[/php]
Jun 16 '06 #2

P: 2
I tried that but still got the access denied problem as before with the javascript declaration line in lower.php. Is there any reason that php scripts would not be able to access the other frame?
Jun 19 '06 #3

P: 5
I dont know if you want to rebuild your entire site, but I built one of my sites with the look of frames using php. Here is the site that helped me build it.
http://www.garnetchaney.com/how_to_u...f_frames.shtml

It should hopefully fix your problem
Jun 21 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.