document.open();
document.write("<?include($_SERVER['DOCUMENT_ROOT'].'/begin.php');?>");
document.close();
Nothing shows up. Why? And what should I do to fix this?
document.open();
document.write("<?include($_SERVER['DOCUMENT_ROOT'].'/begin.php');?>");
document.close();
Nothing shows up. Why? And what should I do to fix this?
include returns either true or false.
you prob want something like
$data = file($_SERVER['DOCUMENT_ROOT'] . '/begin.php');
foreach($data as $line) {
echo "document.write('" . addslashes(trim($line)) . "');\n";
}
Error on page and nothing happens at all.
<script language="JavaScript">
<!-- hide from old browsers
function WritePage()
{
<?
document.open();
$data = file($_SERVER['DOCUMENT_ROOT'].'/begin.php');
foreach($data as $line)
{
echo "document.write('" . addslashes(trim($line)) . "');\n";
}
document.close();
?>
}
//-->
</script>
Same with this:
<script language="JavaScript">
<!-- hide from old browsers
function WritePage()
{
document.open();
<?$data = file($_SERVER['DOCUMENT_ROOT'].'/begin.php');
foreach($data as $line)
{
echo "document.write('" . addslashes(trim($line)) . "');\n";
}
?>
document.close();
}
//-->
</script>
<?php
$data = file('http://yoursite.com/begin.php');
echo "<script type=\"text/javascript\">\n";
foreach($data as $line) {
echo "document.write('" . addslashes(trim($line)) . "');\n";
}
echo "</script>";
?>
use your full domain sothe php page is parsed.. then this should work.
The php code inside the javascript tags causes nothing in the script to work at all.
<? $start="<script type='text/javascript'>\n"; $end="</script>"; ?>
<script language="JavaScript">
function WritePage()
{
alert("in"); //never gets here
document.open();
<?php //without removing these.
$data = file('http://foryouandi.com/begin.php');
echo $start;
foreach($data as $line)
{
echo "document.write('" . addslashes(trim($line)) . "');\n";
}
echo $end;
?>
//document.write("Hi");
document.close();
}
</script>
Is what I am trying to do impossible? Because php is server side and javascript is client.
http://www.neoprogrammers.com/code/4u.php - view that and view source
source code is
<?php
$data = file('http://foryouandi.com/begin.php');
echo '<script type="text/javascript">';
foreach($data as $line) {
echo "document.write('" . addslashes(trim($line)) . "');\n";
}
echo '</script>';
?>
You have been extremely helpful. I'm not so sure we are on the same page. I need to call this script whenever the user clicks a link on the page:
<A href="javascript:WritePage()">1-5</A>
But that does not work and I think I'll give up on php code inside javascript.
I made new code without direct javascript but I don't know how to call it from a link:
<?
function WritePage()
{
$data = file('http://foryouandi.com/begin.php');
echo "<script type='text/javascript'>";
echo "document.open();";
foreach($data as $line)
{
echo "document.write('" . addslashes(trim($line)) . "');\n";
}
echo "document.close();";
echo '</script>';
}
?>
//Try to call:
<A href="php:WritePage()">1-5</A> //no
<A href="WritePage()">1-5</A> //no
I do believe that is impossible. PHP is evaluated on the server before the HTML hits the browser. Javascript executes in the browser, usually as or after the page has loaded.
i see what you are saying. there is a new(er) way to get javascript to dl http pages. heres an article.
http://jibbering.com/2002/4/httprequest.2004.html
Thanks, but that looks like a M$ implementation to me; I'll pass.
its cross browser compatible and works in all os's. see maps.google.com for examples of it.
Thanks, I know how to make frames. But I don't see them on many pages and I am wondering why? For example, the sidebars on many pages don't use frames and I think they should...I'm confused.