SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Lost
    Join Date
    Dec 2002
    Location
    Norway
    Posts
    225
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Make something show only on some parts of a website - help please

    I'm kinda stumped here. I have a site where I want to show a html code if the the url is www.tld.com/pris/*anythinghere* but not if the url is TLD Information Technology specialists without anything more.

    Example: I go to CNN.com - Breaking News, U.S., World, Weather, Entertainment & Video News -> nothing shows, then I move on to www.cnn.com/pris/ the html code shows.

    I know how to do this with php but I have to use javascript here.

  2. #2
    SitePoint Enthusiast adityamenon90's Avatar
    Join Date
    Apr 2010
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    embed jquery in your document.

    also, code in an empty div in your markup, with the id "only-if-url"

    then, create a separate javascript file and code it something like this:
    Code:
    $(document).ready(function() {
        var pathname = window.location.pathname;
        //do a regex search here for strings starting with (www.tld.com/pris/*anythinghere*)
        //or all of its cousins including those that have http:// before, the ones without www
        //etc., if it matches, then do the following
       {
            $("#only-if-url").html("your dynamic stuff here");
        }
        else
        {
            //do nothing
            return false;
        }
    });


Bookmarks

Posting Permissions

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