SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2002
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Including Files With Javascript (not document.write)

    Hi,
    Is there any way to include files with javascript without using document.write('');? The reason for this is the file I am trying to include is a full html page with line breaks and gives me errors using the above method. Server side includes will not work in this case and I would prefer not to use IFRAMES.
    Thank You,
    Pawel Kowalski

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I'm pretty sure the only way you're going to include the entire page via JavaScript is with document.write()

    You can't use PHP, ASP, or an SSI-included CGI script?

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2002
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I might be able to use php to download the page, however, that takes a lot of resources so I would like to use javascript if at all possible. Is there anyway to make document.write() support line breaks?
    Thank You,
    Pawel Kowalski

  4. #4
    The short answer is yes... Herbster's Avatar
    Join Date
    Oct 2001
    Location
    Bay City, Oregon
    Posts
    715
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are the line breaks required for formatting or do they just show up as a consequence of using an editor? If you don't need them, strip them out beforehand - or replace them with spaces. If you need them, replace them with <br />'s.

  5. #5
    SitePoint Enthusiast
    Join Date
    Oct 2002
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Herbster
    Are the line breaks required for formatting or do they just show up as a consequence of using an editor? If you don't need them, strip them out beforehand - or replace them with spaces. If you need them, replace them with <br />'s.
    Unfortunately there is no way to this as it would require 100s of pages to be edited, and I don't own those pages so I would have to ask the owner to change them (very unlikely).
    Thank You,
    Paul

  6. #6
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you're talking about linebreaks like this

    document.write('<html>
    </html>');

    Which you know doesn't work - it's an unterminated string. You can, however, do it either of the following two ways

    document.write('<html>');
    document.write('</html>');

    document.write(
    '<html>' +
    '</html>'
    );
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  7. #7
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    could you not create an object in HTML then change the innerHTML or the nodes of that object?

    you can also use
    Code:
    document.write('<html><a href="#" onmouseover="function(\'object\','+variable+');2ndFunction()"></a></html>')
    so long as all the html is inline. You can use commas as well.
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  8. #8
    SitePoint Enthusiast
    Join Date
    Oct 2002
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Unfortunetly both of the methods won't work. I need it so I can include a page like
    Code:
    <html>
    <head>
    <title>whatever</title>
    </head>
    <body>
    Test<br>
    line break<br>
    another line break
    </body>
    </html>
    Notice how there are 10 line breaks in the above. Is there any way to include that without having to change to
    Code:
    <html><head><title>whatever</title></head><body>Test<br>line break<br>another line break</body></html>
    If there is an easy way to include it with php then it might also work.
    Thank You,
    Paul

  9. #9
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Save it in a file and include(file); in PHP

  10. #10
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ya - JS won't do what you need. Use PHP fo' sho
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev





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
  •