Solved

Find out what page I'm on

Posted on 2011-09-12
7
249 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

820 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