Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / October 2007



Tip: Looking for answers? Try searching our database.

If Statement

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
cgt1801@yahoo.com - 25 Oct 2007 01:47 GMT
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.
Stevo - 25 Oct 2007 09:04 GMT
> 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
[quoted text clipped - 6 lines]
> 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
Doug Miller - 25 Oct 2007 13:10 GMT
>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
[quoted text clipped - 4 lines]
>http://example.com/
>http://example.com/index.html

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

Signature

Regards,
       Doug Miller (alphageek at milmac dot com)

It's time to throw all their damned tea in the harbor again.

Thomas 'PointedEars' Lahn - 25 Oct 2007 16:39 GMT
>> 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
[quoted text clipped - 6 lines]
>
> 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
Signature

Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee

Bart Van der Donck - 25 Oct 2007 16:48 GMT
> In article <ffpimr$sqp$0...@news.t-online.com>, Stevo <ple...@spam-me.com> wrote:
>>Remember that if your default page is index.html, then that might not
[quoted text clipped - 7 lines]
>
> Yes, and I think you can add http://example.com/index.htmto that list, too.

Always adding the 'www.'-prefix is safer. I remember a tough debug
session on Apache where the aliasing from example.com to www.example.com
was not present in httpd.conf by default.

--
Bart
Thomas 'PointedEars' Lahn - 25 Oct 2007 11:15 GMT
> 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
Signature

Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee

Tim Ferguson - 31 Oct 2007 20:05 GMT
cgt1801@yahoo.com wrote in news:1193273248.312901.121690
@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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.