Cory Posted October 29, 2007 Share Posted October 29, 2007 Hello there, question: Is it possible to host HTML externally (as you can do with JavaScript)? I'm guessing the only way to host HTML externally is through JavaScript, like so: document.write("<b>Hello World!</b>") I can externally host that, however, when I insert a full HTML table between the document.write tag the HTML won't appear when I place the externally hosted JavaScript snippet in the web file. Will externally hosted scripts exempt certain HTML tags or something? Link to comment Share on other sites More sharing options...
Err Posted October 29, 2007 Share Posted October 29, 2007 Have you looked into PHP Include?http://www.w3schools.com/php/php_includes.asp Link to comment Share on other sites More sharing options...
Cory Posted October 30, 2007 Author Share Posted October 30, 2007 I'll take a gander at it.Thanks for the link.However, is there a way to host HTML with JavaScript? Link to comment Share on other sites More sharing options...
jlhaslip Posted October 30, 2007 Share Posted October 30, 2007 Yes, all you do is 'write' the html as per above. Link to comment Share on other sites More sharing options...
Cory Posted October 30, 2007 Author Share Posted October 30, 2007 I've tried that, though. When I host "<b>Hello World!</b>", it works. However, when I host a complete table within the document.write line, it doesn't work.Works: document.write("<b>Hello World!</b>") Doesn't Work: document.write("<table border=1><tr><td>row 1, cell 1</td><td>row 1, cell 2</td></tr><tr><td>row 2, cell 1</td><td>row 2, cell 2</td></tr></table>") Does the 2nd code work for you, when hosted? Link to comment Share on other sites More sharing options...
jlhaslip Posted October 30, 2007 Share Posted October 30, 2007 I don't do js. you will need to have another opinion. Link to comment Share on other sites More sharing options...
justsomeguy Posted October 30, 2007 Share Posted October 30, 2007 That specific example should work. If you have quotes in the HTML text make sure you are escaping them. Link to comment Share on other sites More sharing options...
Nim199 Posted October 30, 2007 Share Posted October 30, 2007 I am no expert, but I would have thought that with multiple lines you would need either write out 'document.write("###")' lots of times, or put some braces in somewhere ({}). Link to comment Share on other sites More sharing options...
justsomeguy Posted October 30, 2007 Share Posted October 30, 2007 No, the string ends at the second double quote, all of the newlines are printed as newline characters. Link to comment Share on other sites More sharing options...
Cory Posted October 31, 2007 Author Share Posted October 31, 2007 <script type="text/javascript" src="http://209.85.12.234/11169/126/upload/p10513531.ibf"></script> http://209.85.12.234/11169/126/upload/p10513531.ibfTried that; didn't work. Parenthesis have been exempt. Link to comment Share on other sites More sharing options...
paynekj Posted October 31, 2007 Share Posted October 31, 2007 To get your included javascript document.write to work over mulitple lines you need to "escape" the new-line characters using a backslash:Taken from my own web-site to include my navigation menu into all my pages:Saved as galnavmenu.js: document.write('\<br />\<dl id="navmenu1">\ <dt id="NavHeader">Navigation Menu</dt>\ <dd class="navbar1" id="home1"><a href="../../index.html" title="HOME">Home</a></dd>\ <dd class="navbar1"><a href="../gal02_stuff/index.html" title="Stuff">Eclectic</a></dd>\ <dd class="navbar1"><a href="../gal03_simp/index.html" title="Simple">Minimal</a></dd>\ <dd class="navbar1"><a href="../gal04_sun/index.html" title="Sun">Sun</a></dd>\ <dd class="navbar1"><a href="../gal05_stone/index.html" title="Stones">Standing Stones</a></dd>\ <dd class="navbar1"><a href="../gal06_flow/index.html" title="Flowers">Flowers</a></dd>\ <dd class="navbar1"><a href="../gal07_bw/index.html" title="Monochrome">Black and White</a></dd>\ <dd class="navbar1"><a href="../gal08_arch/index.html" title="Archery">Archery</a></dd>\ <dd class="navbar1"><a href="../places/index.html" title="Places Galleries">Places</a></dd>\ <dd class="navbar1"><a href="../reflect/index.html" title="Reflections">Reflections</a></dd>\ <dd class="navbar1"><a href="../others/index.html" title="others">Techniques</a></dd>\ <dd class="navbar1"><a href="../new/index.html" title="new">New</a></dd>\ <dd class="navbar1"><img src="../../copywi.png" width="102" height="27" alt="" id="copyw" title="© 2007 kevin payne" /></dd>\</dl>\<!-- </div> -->\<br />\'); Then included in each page using <script src="../galnavbar.js" type="text/javascript"></script> <!-- include the navigation bar --> Hope this helpsKevin Link to comment Share on other sites More sharing options...
aspnetguy Posted October 31, 2007 Share Posted October 31, 2007 if you server supports SSI (server side includes) you can just do this with externale files. The external files should not contain <html>, <head>, or <body> tags. <!--#include file="file.html"--> Link to comment Share on other sites More sharing options...
Cory Posted November 1, 2007 Author Share Posted November 1, 2007 You, paynekj, are awesome. :)Your method is just what I was looking for. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.