Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-01-2007, 05:25 PM   PM User | #1
jonquinn
New to the CF scene

 
Join Date: Sep 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
jonquinn is an unknown quantity at this point
URL based conditional comment

Hello. I am trying to create a conditional comment scenario that is based on a web address. I am working with an ecommerce site that I want to put a nav menu promotion on all the pages except the home page. The system we are using only allows a post promotion to ALL or one specified URL.

I have tried everything I can think of to create a URL condition based comment but nothing has worked. I tried modifying the code below to change the if output to a variable comment tag and then write the variable further in the script with a document.write.

<SCRIPT LANGUAGE="JavaScript">
<!--
url=location.href
if (url=="http://www.sitename.com") {alert("Welcome To sitename")}
else {alert("welcome")};
// -->

Any help would be greatly appreciated.
jq
jonquinn is offline   Reply With Quote
Old 09-01-2007, 07:19 PM   PM User | #2
Arbitrator
Senior Coder

 
Arbitrator's Avatar
 
Join Date: Mar 2006
Location: Splendora, Texas, United States of America
Posts: 2,902
Thanks: 5
Thanked 188 Times in 185 Posts
Arbitrator is on a distinguished road
Quote:
Originally Posted by jonquinn View Post
I am trying to create a conditional comment scenario that is based on a web address. I am working with an ecommerce site that I want to put a nav menu promotion on all the pages except the home page. The system we are using only allows a post promotion to ALL or one specified URL.

I have tried everything I can think of to create a URL condition based comment but nothing has worked.
Code:
<script type="text/javascript">
	<!-- The deprecated media type text/javascript is used over the media types application/javascript and application/ecmascript for Internet Explorer compatibility. -->
	var d = document;
	if (/^http:\/\/www\.sitename\.com\/(\?.{3,})?(#.+)?$/.test(d.URL)) {
		// do something
	}
	else {
		// do something
	}
</script>
The above code accounts for query strings (e.g., http://www.sitename.com/?parameter=value) and fragment identifiers (e.g., http://www.sitename.com/#fragment).

It doesn’t account for the omission of “www.” (e.g., http://sitename.com/), which your server may or may not allow; pages that might use the HTTPS scheme (e.g., https://www.sitename.com/); port numbers (e.g., http://www.sitename.com:port/; or pages that misuse fragment identifiers (e.g., http://www.sitename.com/# from href="#" or elsewhere).

Quote:
Originally Posted by jonquinn View Post
I tried modifying the code below to change the if output to a variable comment tag and then write the variable further in the script with a document.write.
document.write is poor practice. Use DOM Core methods instead.

Quote:
Originally Posted by jonquinn View Post
<SCRIPT LANGUAGE="JavaScript">
<!--
url=location.href
if (url=="http://www.sitename.com") {alert("Welcome To sitename")}
else {alert("welcome")};
// -->
Don’t put SGML comment tags around your scripts (<!-- and -->) or use the deprecated language attribute. For the latter, use the type attribute instead. If you’re just looking for the current URL, then the DOM2 HTML document.URL is a better choice than the non‐standard location.href.
__________________
Please for the love of god stop making IE. You current "browser"s cause me to cry every day. —Phil *
Arbitrator is offline   Reply With Quote
Old 09-03-2007, 06:04 PM   PM User | #3
jonquinn
New to the CF scene

 
Join Date: Sep 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
jonquinn is an unknown quantity at this point
Can scripts

Thanks for the help. I know very little about java, my programing experience was Qbasic and a little C++ so please forgive my ignorance.

I am trying to make adsense show up on every page except the homepage. Since adsense is a script and I just realized I can't nest scripts, is there a different way to keep the script from executing if the url doesn't contain any kind of identifiers? The homepage is default.asp but it is masked as just http://www.site.com/.

Sorry if you answered this and I am just a little thick.
jonquinn is offline   Reply With Quote
Old 09-03-2007, 06:17 PM   PM User | #4
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
Java is NOT Javascript. Don't confuse them. They are two totally different languages. As to your problem I think you are going about this the wrong way. Just put a boolean variable on the default.asp, set it to true and then check using an if statement. I don't know asp but the psuedo code would look something like this
Code:
if(!booleanvariable)
{ // if not true
// print out google adsense code
}
No other page should have the variable on it so it will always be false and the google adsense code will be outputted.
__________________
||||If you are getting paid to do a job, don't ask for help on it!||||
_Aerospace_Eng_ is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:32 PM.


Advertisement
Log in to turn off these ads.