...

View Full Version : URL based conditional comment



jonquinn
09-01-2007, 05:25 PM
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

Arbitrator
09-01-2007, 07:19 PM
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.
<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).


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.


<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.

jonquinn
09-03-2007, 06:04 PM
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.

_Aerospace_Eng_
09-03-2007, 06:17 PM
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

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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum