LifeInBinary Posted February 28, 2007 Share Posted February 28, 2007 In theory, could you call a .html file from another .html file by doing the following?<script type="text/html" src="link.html"></script>I was wondering... Say I have a DHTML LCD clock that uses images, and I want to put it at the top of every page on a website...It has script that needs inserted in both the head and body of the .html file.So could I set up one .html file that contains only the clock script, then call it from all other pages on my website?Like this:<html><head><!--whatever script I need in the head--></head><body><!--whatever script I need in the body--></body></html>Let's say that is named clock.html - could I call it from a file named index.html by doing this?<html><head><script type="text/html" src="clock.html"></script></head><!--rest of normal file-->Sorry about not using codebox, I didn't think it was enough code to worry about it.Thanks guys,LifeInBinary. Link to comment Share on other sites More sharing options...
jlhaslip Posted February 28, 2007 Share Posted February 28, 2007 Not presently available using html.For this, you need to use a scripting language such as php or asp and "include" the file.Check the w3schools Tutorials. Link to comment Share on other sites More sharing options...
jesh Posted February 28, 2007 Share Posted February 28, 2007 Not presently available using html.For this, you need to use a scripting language such as php or asp and "include" the file.Check the w3schools Tutorials.Or, if you need to rely totally on client-side, you could use document.write to write out the code needed to display the clock:document.write("<div id=\"clock\">The Clock code goes here...</div>"); Or, using the XML DOM, you could create the elements and add them to your document: var div = document.createElement("div");div.id = "clock";div.appendChild(document.createTextNode("some text would go here"));document.body.insertBefore(div, document.body.firstChild); Link to comment Share on other sites More sharing options...
jlhaslip Posted February 28, 2007 Share Posted February 28, 2007 I don't javascript. Link to comment Share on other sites More sharing options...
jesh Posted February 28, 2007 Share Posted February 28, 2007 heh Link to comment Share on other sites More sharing options...
LifeInBinary Posted February 28, 2007 Author Share Posted February 28, 2007 Or, if you need to rely totally on client-side, you could use document.write to write out the code needed to display the clock:document.write("<div id=\"clock\">The Clock code goes here...</div>"); Or, using the XML DOM, you could create the elements and add them to your document: var div = document.createElement("div");div.id = "clock";div.appendChild(document.createTextNode("some text would go here"));document.body.insertBefore(div, document.body.firstChild); I would like to stay client-side on this one. This is stupid I know, but is that JavaScript or CSS? Also, could I just put that document.write code in a seperate file and call to it from the .html file?Could you give me an example of how I could do this?Also, XML DOM is very foriegn to me - so at least for now, that's going out the window, lol - no offense.Thanks for the help,LifeInBinary. Link to comment Share on other sites More sharing options...
croatiankid Posted February 28, 2007 Share Posted February 28, 2007 it's javascript. mind you many people have js disabled so this isn't really preferable. By the way you can use SSI (server side includes)- they don't require php or asp or python or whatever. this explains it awesomely Link to comment Share on other sites More sharing options...
reportingsjr Posted February 28, 2007 Share Posted February 28, 2007 ^^ If the way to do this is through server side includes, it CAN be done through html, just not with the .html extension. Also your host must support it (if this is on the intranet (files on your computer in the browser) then it will work). You just have to use the .shtml extension. Link to comment Share on other sites More sharing options...
LifeInBinary Posted February 28, 2007 Author Share Posted February 28, 2007 mind you many people have js disabled...I heard there was a way to 'force' your viewers to run your JavaScript. Do you know anything about this?Thanks,LifeInBinary. Link to comment Share on other sites More sharing options...
justsomeguy Posted February 28, 2007 Share Posted February 28, 2007 You can't force Javascript to be enabled if the user has disabled it. And for good reason, if I had it disabled I wouldn't want someone else enabling it. You can also use an iframe to show another HTML document.<iframe src="clock.html" /> Link to comment Share on other sites More sharing options...
croatiankid Posted March 1, 2007 Share Posted March 1, 2007 You could use an IFRAME yes, but I wouldn't suggest it. I have seen some REALLY wierd problems it can cause in Firefox lol. Yes thank god js can't be forced, that's as good as giving someone the password and location of your computer and all its files. Link to comment Share on other sites More sharing options...
Skemcin Posted March 1, 2007 Share Posted March 1, 2007 if you want HTML brought in to a page as you mention, then a.) you would have to write your HTML in javascript form and then call the javascript using the <script> tag - as previously mentioned.Why do this? Well, if you do not have knowledge or access to server side scripting languages, then you can use this method to simulate server side includes.b.) you could write that HTML into a seperate file and use server side includes (SSI) which are explained in the ASP Tutorial in W3Schools - but it doesn't require ASP, HTM files can use them if the hosting provider has them enabled.Why Do This? Ideal for maintaining reused code as well as your sanity. Typically a site header, footer, and navigation are the first to put pulled into SSI files. Then you can get creative and code applications as includes so you can literally cut-n-paste a page together solely on includes.c.) you could write that HTML into a seperate file and use <iframes>. It is an internal frame that reserves a fixed space on a page to embed a file.Why Do This? This is best for external applications that you might not have any control over - like a google search account you might open for your site. The application runs in the frame while you still have control of the outer inteface. I've done this several times, most recently a photographer site that allows its clients to create a gallery that is pulled into their own site by calling a page on the photographers site via <iframe>I think you are leaning toward a server side include (SSI) Link to comment Share on other sites More sharing options...
LifeInBinary Posted March 1, 2007 Author Share Posted March 1, 2007 if you want HTML brought in to a page as you mention, then a.) you would have to write your HTML in javascript form and then call the javascript using the <script> tag - as previously mentioned.Why do this? Well, if you do not have knowledge or access to server side scripting languages, then you can use this method to simulate server side includes.b.) you could write that HTML into a seperate file and use server side includes (SSI) which are explained in the ASP Tutorial in W3Schools - but it doesn't require ASP, HTM files can use them if the hosting provider has them enabled.Why Do This? Ideal for maintaining reused code as well as your sanity. Typically a site header, footer, and navigation are the first to put pulled into SSI files. Then you can get creative and code applications as includes so you can literally cut-n-paste a page together solely on includes.c.) you could write that HTML into a seperate file and use <iframes>. It is an internal frame that reserves a fixed space on a page to embed a file.Why Do This? This is best for external applications that you might not have any control over - like a google search account you might open for your site. The application runs in the frame while you still have control of the outer inteface. I've done this several times, most recently a photographer site that allows its clients to create a gallery that is pulled into their own site by calling a page on the photographers site via <iframe>I think you are leaning toward a server side include (SSI)Yes, when I researched into this I had come to the conclusion that SSI is probably what I need...Now about the first option - just because it sounds easier and more likely to be available on free hosting.Would it look like this?<script type="text/javascript"><html><head>The contents I need for the head of what I'm inserting...</head><body>The contents I need for the body of what I'm inserting...</body></html></script> and then I would call that .js file from the .html?So if I had a clock that I wanted displayed at the top of every page for example, I would just insert a link to that .js into the begining of every page?And I would put the clock's HTML and JavaScript into that special .js containing HTML?Sorry to sound confusing, but thanks for the help,LifeInBinary. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now