Jump to content
xisto Community
Sign in to follow this  
switch

Integrating One Html File Into Another without embedding

Recommended Posts

Hey guysI'm overhauling my website and have decided instead of using frames I want to just have a logo and buttons integrated into each HTML file, so you can just scroll down past it. I want the logo at the very top, before any content.I was wondering if there is any way of doing it with an HTML tag (i.e. not PHP or any other scripts) so the header just gets inserted right after the opening <BODY> tag. I'm thinking that possibly it uses the <link> tag, but really I don't have much of an idea.Thanks in advance for your suggestions.Peace out :P

Share this post


Link to post
Share on other sites

I think the simplest way to do this is to use a javascript that has the information you want and then insert the script in the page where you want it. Unlike PHP or ASP etc. a javascript will work on almost any web host, essentially it is just inserting a text file.

Here's a very simple example for inserting a logo image and some buttons, note the use of single quotes around the image and page names.

document.write("<img src='my_logo.jpg'><br>")document.write("<a href='contact_page.html'><img src='contact_button.jpg'></a><a href='search_page.html'><img src='search_button.jpg'></a><a href='gallery_page.html'><img src='gallery_button.jpg'></a>")

Save the above text in a file called 'mynav.js' and upload it to your web server. Then to display it on a page, just insert the following script tags at the position on the page where you want it to display, in your case it would be immediately after the '<BODY>' tag as shown below.

<html><head><title>My Web Site</title></head><BODY><script src="mynav.js"></script>The rest of your page code goes here....
You can use pretty much any html code you like, just so long as you replace any double quotes (") with single quotes ('). Experiment a little to see what you can do. As you can see from the example above, if you are going to insert a large amount of html, you can do multiple 'document.write' statements.

I hope that helps. :P

Share this post


Link to post
Share on other sites

Avalon,If your approach is used, does the html code you insert via javascript get the css applied to it if the css is in a css file?

Share this post


Link to post
Share on other sites

In my website, i gave up with standard frames because in my opinion, they looked pretty ugly and most web-authoring programs nowadays include framed pages as part of their standard templates, hence meaning users think you're just using a template rather than actually going ahead and creating the website yourself.I have, in the past, used IFrames, still based along the idea of frames, although they allow you to place frames almost anywhere on your webpage, meaning you don't have to worry about loads and loads of code.Only problem with frames, or anything relating to frames, is that not all internet browsers support these (yet). It's best to use php when at all possible. Even WebTV, a prime example of a basic browser, can access the php and perform the functions. If you can't use php, try to use tables in html!Hope this helps :P

Share this post


Link to post
Share on other sites

I think the simplest way to do this is to use a javascript that has the information you want and then insert the script in the page where you want it. Unlike PHP or ASP etc. a javascript will work on almost any web host, essentially it is just inserting a text file.

It may work on almost any host, but unlike server side scripting languages, javascript can be turned off which means that users of your site will be missing whole chunks of the page. W3Schools figures show that about 10% of users have js turned off which is a very large slice of your audience who won't be able to use your site properly (especially if you're using it to display your navigation.
Stick with server side includes (they can be configured to work with HTML, no scripting languages required) - they're the industry standard.

Share this post


Link to post
Share on other sites

It may work on almost any host, but unlike server side scripting languages, javascript can be turned off which means that users of your site will be missing whole chunks of the page. W3Schools figures show that about 10% of users have js turned off which is a very large slice of your audience who won't be able to use your site properly (especially if you're using it to display your navigation.

Stick with server side includes (they can be configured to work with HTML, no scripting languages required) - they're the industry standard.

209162[/snapback]

You make an excellent point, I didn't realise that many people turn off js. To clarify things a little here, perhaps you could explain what server side includes are, how to use them and any restrictions they impose.

 

@jlhaslip Yes, the html you insert is affected by css like the rest of the page.

Share this post


Link to post
Share on other sites

To clarify things a little here, perhaps you could explain what server side includes are, how to use them and any restrictions they impose.

They work in a very similar way to the js method you posted. You create a file with the piece of code that's to be inserted into another file and then you write a line of code in that file that calls the include. For PHP it looks like this:

<? php include('yourfile.htm') ?>
In ASP and HTML it looks like this:

<!-- #include virtual="/yourfile.htm" -->
Some configuration of the server is required to get it to work for HTML as it is not usually enabled by default. PHP, ASP, JSP, Coldfusion etc. all enable them by default.
You can call any file to include in your document: .htm, .txt, .inc, .asp, .php. In fact, you can write scripting code in a .txt file and it'll work as intended if it is included in a file with the relevant extension (e.g. .asp or .php).
I'm not aware of any restrictions (except if you're server isn't configured to accept them which wouldn't be the case if you're using Xisto). The benefits over the js method is that they can't be turned off and rather than being written to the page as javascript, they get written as HTML (or whatever else you've included).

Share this post


Link to post
Share on other sites

ok, thanks everybody, i'll definately take a look at that.i'm sort of actually leaning more towards a client side thing though, would there be any feasible way of doing that?thanks heaps for your help and advice guys, i really appreciate it :P

Share this post


Link to post
Share on other sites

i'm sort of actually leaning more towards a client side thing though, would there be any feasible way of doing that?

 

Why are you leaning towards client side when, as already pointed out (twice), if it's client side, the client can turn it off (whether intentionally or not)? Which when you're talking about the actual code of your site, is a bad thing.

Share this post


Link to post
Share on other sites

Doesnt it work if you put whatever you want, for example pure html or xhtml, or even css in a file called wathever.js instead of print: <div>...</div> ?

Share this post


Link to post
Share on other sites

i like to use <iframes> and some php includes, thinking of using javascript makes me lazy, because in some explorer they don't work quite well (at least for me, maybe i did them wrong =P) you can also try php includes by using <? include("page.php/inc"); ?> i havent tried it in html or htm files but it sures works fine with me =)

Share this post


Link to post
Share on other sites

Doesnt it work if you put whatever you want, for example pure html or xhtml, or even css in a file called wathever.js instead of print: <div>...</div> ?

I've said this 3 times already! If it's JS, it can be turned off!!!! :P

Share this post


Link to post
Share on other sites

Yes, dont get mad, and please first read the whole question to avoid misunderstaning, im talking about the js file, not the agent support, im asking if the file itself can contain html code without the need of using the "print" js command...Please read and understand... dont get mad :P

Share this post


Link to post
Share on other sites

hmm... lozbo, that's a really interesting idea! although i think that some super agressive browsers may try to block it. Tyssen has a good point about using server side integration though. The main reason why i don't want to do that is because it sorta slows things down a bit.... but i guess that doesn't matter alot when you don't get alot of heavy traffic anyway.Tyssen, do you know if HTML 'include' statements are enabled by default on Xisto? You sort-of implied that they were (or at least that Xisto allowed 'include' statements) but were kind of vague in this area. Thanks for all your help guys. Much appreciated ;)peace out :)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.