Results 1 to 3 of 3

Thread: File include with JavaScript.

  1. #1
    Join Date
    Apr 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation File include with JavaScript.

    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.
    Code:
    <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);
              head.appendChild(script);
            } else {
              alert('Your browser can\'t deal with the DOM standard. That means it\'s old. Go fix it!');
              }
            }
    </script>
    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:
    Code:
    <?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:
    Code:
    <?php echo "document.write('yo yo yo yo');"; ?>
    ==> Nothing happens. No text is displayed. WHY??

    Thanx...

  2. #2
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    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

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •