Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Sep 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,338
    Thanks
    29
    Thanked 282 Times in 276 Posts
    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.
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #3
    New to the CF scene
    Join Date
    Sep 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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!||||


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •