Jump to content
castorp

'huh? - A question regarding HTML' by me

Recommended Posts

Dear Thumb-folk,

I have a HTML-question, and as I am scared of the internet in general and only feel comfortable around these parts, I dare to pose it here.

As further introduction, I am HTML-self-taught, and while I am quite comfortable with the solutions I find for the problems I have, they might be the dumbest shit on both ends. I tried the internet, found something, was pleased, but now feel like it's not a solution at all – all the other related stuff I didn't understand well.

So anyway, someone wants me to get rid of frames, as in, he doesn't want to use them, because the internet says they are bad, but still wants a menu to be separate so he can alter it at will without going through every page that includes it. Said person is not willing to use Dreamweaver or the like, so this apparent solution is sadly not available.

I managed to do it as frames do with the 'object'-element, but am unsure, whether this is in any way better than frames themselves. With 'object' I managed to include a html-page, the menu-page, in another one, and make it look like before. Somewhere was written that this is better (at a site for barrier-free internet), but for me it looks the same as frames, just without that specific construction.

Server-Side-Includes I do not understand at all, and I am unsure whether that stuff would even be available. CSS only does design in my world, so they can't help (can they?).

My questions:

Is the 'object'-element-solution in any way better than frames?

Do you people have another great idea (it doesn't have to be super-simple, but super-hard would be even worse)?

Are SSI the way to go?

Thanks, people

castorp

Share this post


Link to post
Share on other sites

Frames are a deprecated element, which means soon enough browsers will no longer support them (although I doubt any time soon). Furthermore, search engines do not properly know (or don't want to) spider framed websites because it is inconsistent and too variable to do so; therefore, are penalized in their results and sometimes ignored all together. I know you didn't ask that, but I thought I'd share :)

The easiest way would be to use just a touch of PHP - you don't need any programming to do this. Have two files:

menu.php

index.php

In the index.php (or the other pages) have the following code where you want the menu to show up:

<?php require_once(menu.php) ?>

And that's all you need, just include that line on any page where ever you want to include the code that is in the menu.php. Of course, because this is an SSI, you will need web server emulator on your machine, or just test live on a web server. I recommend XAMMP if you want a good web server package on your local machine.

Share this post


Link to post
Share on other sites

Local staging may be too much bother for something this simple. You just have to make sure your server has PHP. Any PHP will do. If you don't have any kind of scripting, you can do AJAX. Jquery makes it fairly simple. But your website will not be indexed by spiders at all, so this might not be a solution at all.

Include this inside your head tag:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8">
 $(document).ready(function(){
    $.post('/myMenuFile.html', function(data) { $('#menuElement').html(data); });
 });
</script>

And then make sure you have an empty div with an id of menuElement in your code. It should pull the content from the myMenuFile.html. This solution is no better or worse than using frames. Ideally you would want to use server-side includes or PHP like suggested above.

Share this post


Link to post
Share on other sites
Try turning it off and then on again. I find this sorts most computer problems.

No need to thank me.

gt9j80Jkc_A

Share this post


Link to post
Share on other sites

Server Side Includes is what you need (unless you're using ASP.NET, which case you could use a Master Page). Yes, I know that was no help, but Google might set you off on the right path :) (If everyone's answers here aren't good enough.)

Also, SuperUser.com is an awesome place to get answers to well asked questions (not that there's any problem with asking here).

Share this post


Link to post
Share on other sites
Also, SuperUser.com is an awesome place to get answers to well asked questions (not that there's any problem with asking here).
Ooh, that looks neat. And useful.

Share this post


Link to post
Share on other sites

Oh, cool stuff, thanks.

/me bookmarks

I just noticed something I forgot to mention: if you decide to go with jQuery/AJAX, the menu file doesn't have to be a proper html document with all the <html><head></head><body> Blargh </body></html> stuff. You just need to put in the <ul> that you want to insert or whatever.

Share this post


Link to post
Share on other sites

Thanks a lot for all the answers. I will read up on SSI and .php when I find the time. And thanks for the link, Thunder, I bookmarked it as well.

(But since I started here...)

Just this:

So my object-solution is worthless? It seems it at least makes it future-proof, as I don't use the 'frames'-element anymore. But I guess, all the other problems remain - the readability issue for text-only browsers ('barrier-free internet'-stuff), the thing with the search-engines - ?

Now the dumb/ignorant part:

So this SSI - so elements are handled by the server - but aren't all websites on servers, so what's the difference? And the menu-php is basically an html-file without head and body tags and the ending .php?

(Sorry if it looks like I'm just too lazy to do the research. I did try to read up on it before, but somehow I didn't understand it properly right away, and right now I am swamped with work and new stuff and just don't have that much engery left.

So, just ingnore if it bothers you.)

Thanks folks

castorp

Share this post


Link to post
Share on other sites

Your object solution is just bizarre and I am not entirely sure what it is you did there.

PHP is a scripting language. The server (say, Apache) is told to read the files with the php extension as scripts and execute them. The stuff that is not php will be output as if it were plain html. Stuff that looks like C code will be executed in much a similar way as C gets executed. So, php allows you to interweave complex commands and dynamic elements with plain static html elements. That is all.

The line of code that Drath suggested basically tells the server which is serving the content to the client, When you get to this point in the content, drop whatever blob of text you find in this other file as if it is content of this first file that the client asked for. The visitor doesn't know that you linked to another file, the shit happens entirely on your server, for your benefit; namely, now you have one menu file to edit and it updates across all pages that include it. When you visit the site on the front end, through your browser, and click VIEW PAGE SOURCE, the source you will see will be the one cobbled together from all the disparate files that you've included. The PHP will never show up in this view, since it has been executed by the server.

You should also consider having a header and footer in their own files, so that each requested page only has content, and the rest of the elements are standardized.

Share this post


Link to post
Share on other sites

Ah, thanks for your explanation. Now I understand. And it does sound pretty doable.

('bizarre', hehe, yeah, sounds like a fitting adjective for my way of doing html - I included something with the 'object'-element, said something being another html-file with only the menu. So on the content-carrying html is a small window that is full of the menu-html. Looks like before, but now the menu is separate. As said, for me it looks like frames without using that element.)

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

×