?
Solved

Find out what page I'm on

Posted on 2011-09-12
7
Medium Priority
?
252 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 58

Accepted Solution

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

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

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

DOM Attributes and Properties treatment with jQuery 1.6 by Ivo Stoykov jQuery (http://jquery.com/) 1.6 introduces .prop() (http://api.jquery.com/prop/) and .removeProp() (http://api.jquery.com/removeProp/) methods which allow modifying or removi…
Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
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)
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…

764 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