Solved

Find out what page I'm on

Posted on 2011-09-12
7
250 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:Tom Knowlton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 53

Accepted Solution

by:
Huseyin KAHRAMAN earned 500 total points
ID: 36523144
try:

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

Expert Comment

by:Huseyin KAHRAMAN
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Author Comment

by:Tom 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:Tom 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:Tom 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
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…

732 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