PDA

View Full Version : Spit out text



skinner927
Apr 24th, 2007, 03:24 AM
Ok, what I want to do is avoid using frames, I know this can be done with frames but I really don't like frames and it will just make my life harder, and the code I'm using probably wont work in a frame.

What I want to do, is save the HTML for my navigation in an external .js file.

Then, in the right spot, call a function that will print it out.

Or, just have the whole head print out, this may be easier, because the code will be at the top of the file.

I don't know much about Javascript, I have used it before and I usually do copy pasting. I don't have a problem with programming though, I know Java and the structure is similar.

THANKS THANKS THANKS! :thumbsup:

nikkiH
Apr 24th, 2007, 02:39 PM
HTML is not javascript, and does not belong in a js file. If you want to just dynamically include an HTML file, you can use server-side includes (if your host supports that). If you're using php or asp, they both have a way to #include a plain file, too.
You should never have your navigation as just pure javascript, as you break the site for non-js browsers and search engines. So I assume you're talking an HTML file that also has javascript for rollovers or some such.

skinner927
Apr 24th, 2007, 09:43 PM
I'm looking for something like this

External Javascriptfile

function printMenu(){
document.write('
<ul id="nav">
<li id="active"><a href="#">PERCONDELI</a>
<ul>
<li><a href="#">Remoras<span>></span></a>
<ul>
<li><a href="#">Echeneis</a></li>
<li><a href="#">Phtheirichthys</a></li>
<li><a href="#">Remora</a></li>
<li><a href="#">Remorina</a></li>
<li><a href="#">Rhombochirus<span>></span></a>
<ul>
<li><a href="#">Echeneis</a></li>
<li><a href="#">Phtheirichthys</a></li>
<li><a href="#">Remora</a></li>
<li><a href="#">Remorina</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#">Tilefishes</a></li>
<li><a href="#">Bluefishes</a></li>
<li><a href="#">Tigerfishes</a></li>
</ul>
</li>

<li><a href="#">ANABODELIA</a>
<ul>
<li><a href="#">Climbing perches</a></li>
<li><a href="#">Labyrinthfishes</a></li>
<li><a href="#">Kissing gouramis</a></li>
<li><a href="#">Pike-heads</a></li>
<li><a href="#">Giant gouramis</a></li>
</ul>
</li>

<!-- etc. -->
</ul>
');

}

Then in the HTML flle, call the function so it will spit it out.


... <tr><td>Javascript:printMenu() </td></tr> ...


I'm sure thats completely wrong, but it gives you more of an idea

nikkiH
Apr 25th, 2007, 04:21 PM
I'd suggest checking out the menus at DynamicDrive.com to get a better idea of the ways to create menus. What you posted isn't very good to do for several reasons. Document.Write is very old, and really shouldn't be used any more. Use DOM methods createElement and appendChild.

You want static text usually, because search engines and other clients (browsers for the visually impaired, mobile browsers, etc) cannot interpret javascript, so you need to have an alternative. Most people these days like the modern approach, which is to use divs and lists, then style it with CSS to create flyout menus as desired, and maybe tweak it with script for MSIE6-.

If you have a section of html that did this that you wanted included on every page, you'd use some type of server-side include. Not javascript. Javascript should ENHANCE the page, but basic functionality such as navigation should never rely on it. As a general rule for most sites, your stuff should never break if a user turns off script.

If what you really want are templated pages, but cannot or do not want to code it yourself, you could use Dreamweaver, Frontpage, or any number of content management systems such as phpNuke, Joomla, or Xoops.