If Statement

C

cgt1801

I want to find a way so that if the javascript is in a certain HTML
document it will write one code and a different document a different
code and so on.

I would like for it to just get the file name of the html document it
is in but if that is not possible i was thinking make a variable for
each document.

Basically im gonna have a nav bar that will be different for some
pages but i like to have it all in one document.
 
S

Stevo

I want to find a way so that if the javascript is in a certain HTML
document it will write one code and a different document a different
code and so on.

I would like for it to just get the file name of the html document it
is in but if that is not possible i was thinking make a variable for
each document.

Basically im gonna have a nav bar that will be different for some
pages but i like to have it all in one document.

If you access top.location.href then you can look at the URL for the
page. You could search for strings in it. Let's assume you have two
pages, page1.html and page2.html on domain example.com

example.com/page1.html
example.com/page2.html

Then you could have logic something like this:

var loc=top.location.href;
var fname=loc.indexOf("/")>-1?loc.substring(loc.lastIndexOf("/")+1):"";

if(loc.indexOf("page1")>-1)
; //do something unique for page1
else if(loc.indexOf("page2")>-1)
; //do something unique for page2
else ; //do something for unknown page (or index.html)

Remember that if your default page is index.html, then that might not
show up in the URL. The following links all work exactly the same when
the default page is called index.html, so you can see that you might not
get a filename at all:

http://example.com
http://example.com/
http://example.com/index.html
 
T

Thomas 'PointedEars' Lahn

Basically im gonna have a nav bar that will be different for some
pages but i like to have it all in one document.

Use server-side scripting instead of client-side scripting.
The former may be an ECMAScript implementation as well.


PointedEars
 
T

Thomas 'PointedEars' Lahn

Doug said:
Yes, and I think you can add http://example.com/index.htm to that list, too.

If, and only if, the server is configured that way, index.html and/or
index.htm are possible. And usually any other "default page" (correct:
"index document" or "directory index") is possible, too. For example,
on my Apache HTTP server I use

DirectoryIndex index.php index.html index.html.var index.htm

Web-authoring basics, really.


PointedEars
 
T

Tim Ferguson

(e-mail address removed) wrote in @v29g2000prd.googlegroups.com:
Basically im gonna have a nav bar that will be different for some
pages but i like to have it all in one document.

.... and no nav bar at all for readers without scripting enabled...


Tim F
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,149
Messages
2,570,842
Members
47,388
Latest member
EarthaGilm

Latest Threads

Top