Solved

Find out what page I'm on

Posted on 2011-09-12
7
247 Views
Last Modified: 2012-05-12
I need to find out what page I am on, then hide a div based on the result.
0
Comment
Question by:knowlton
  • 3
  • 2
  • 2
7 Comments
 
LVL 51

Accepted Solution

by:
HainKurt earned 500 total points
ID: 36523144
try:

if ($(location).attr("href")=="some page") $("#some_div").show();
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 36523163
also you can try these

$(location).attr("pathname")
window.location
window.location.href

0
 
LVL 12

Expert Comment

by:mwochnick
ID: 36523179
to find the path
var pathname = window.location.pathname;

JQuery API documentation on how to hide an element with example code
http://api.jquery.com/hide/
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 5

Author Comment

by:knowlton
ID: 36523180
Can I modify this to see if the location href contains a substring or not?

if ($(location).attr("href")        *=         "some substring") $("#some_div").show();
0
 
LVL 12

Expert Comment

by:mwochnick
ID: 36523195
btw $(location) is not supported, but lots of people use it - http://bugs.jquery.com/ticket/7858
0
 
LVL 5

Author Closing Comment

by:knowlton
ID: 36523280
Perfect.

notes for myself on this solution:

if ($(location).attr("href").indexOf("Book") != -1)
        {
            $('#catalog_name').hide();
        }

Open in new window

0
 
LVL 5

Author Comment

by:knowlton
ID: 36523309
More notes:

It seems this is better:


 var loc = window.location.href;
        if (loc.indexOf("Book") != -1)
        {
            $('#catalog_name').hide();
        }
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I have answered several questions lately that were solved utilizing the power of jQuery's AJAX functions, so I thought I would write an article demonstrating the ease of use. Why should I use jQuery as opposed to regular JavaScript? Now I know…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now