View Full Version : File include with JavaScript.

04-20-2009, 08:13 AM
Hello, I'm confronted with a problem. I'm trying to include PHP on servers that won't allow PHP. I have two servers, one without PHP and one with PHP.
For this I've written a Include funtion in javascript.

<script type="text/javascript">
function include(file) {
if (document.createElement && document.getElementsByTagName) {
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', file);
} else {
alert('Your browser can\'t deal with the DOM standard. That means it\'s old. Go fix it!');
This script is called in de body-section of the non-php document.
<script type="text/javascript">include('http://a-php-server/include.php');</script>

At the php-end I have only one line:

<?php echo "alert('some text');"; ?> ==> This works. My main document shows an alert with some text.

Now, when I replace the alert with a document.write like so:

<?php echo "document.write('yo yo yo yo');"; ?> ==> Nothing happens. No text is displayed. WHY??


04-20-2009, 11:47 AM
without php the echo statement will not be executed

if your php page is very simple the php statements could be stripped out and the remaining text dispayed as innerHTML

04-20-2009, 01:43 PM
You may also want to look at: