/    Sign up×
Community /Pin to ProfileBookmark

making location.pathname.indexOf not case sensitive

I’m trying to figure out how to make this code not be case sensitive when it comes to the “default.asp” line. The code below in the head of a XHTML template and adds the CSS info only on the homepage, which is domain.com or domain.com/default.asp. It works just fine, but when I visit domain.com/DEFAULT.asp it doesn’t work. How do I make it case insensitive?

[CODE]<script type=”text/javascript”>
//<![CDATA[
var onHomePage = (location.pathname == “/”) ||
(location.pathname.indexOf(“/default.asp”) != -1);
if (onHomePage)
document.writeln(“n<style type=’text/css’>#content_area {background-color:#dddddd;}</style>nn”);
//]]>
</script>[/CODE]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@BIOSTALLJul 06.2011 — The best way that I can see would be to convert it to lower case and search for that. For example:

[CODE]var onHomePage = (location.pathname == "/") || (location.pathname.toLowerCase().indexOf("/default.asp") != -1);
if (onHomePage)
document.writeln("n<style type='text/css'>#content_area {background-color:#dddddd;}</style>nn"); [/CODE]


Note the use of the toLowerCase() being used to convert the location.pathname to lower case before comparing it.

Hope that helps
Copy linkTweet thisAlerts:
@mrhooJul 06.2011 — You can also use a regular expression

[CODE]|| //default.asp/i.test(location.pathname))[/CODE]
×

Success!

Help @JayForte spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...