Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-23-2012, 06:52 PM   PM User | #1
mark1ra
New to the CF scene

 
Join Date: Jul 2012
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
mark1ra is an unknown quantity at this point
Unhappy Need help with javascript code

Problem is in website url names, that are generated automaticaly.
1. www.mywebsite.com
2. www.mywebsite.com/wallpapers/show/...
3. www.mywebsite.com/wallpapers/browse_by_size/...
4. www.mywebsite.com/categories/show/...

I need to hide div section only in one type of pages (2 in the list).
So there is the code that I need help with:
Code:
<script type = "text/javascript">
function showMyDiv() {
var url = window.location.href; 
if (/(wallpapers)/i.test(url)) { // the word appears in the url
document.getElementById("hide").style.display="none";
}
else {
document.getElementById("hide").style.display="block";
}
}
</script>
mark1ra is offline   Reply With Quote
Old 07-23-2012, 07:15 PM   PM User | #2
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 941
Thanks: 7
Thanked 95 Times in 95 Posts
WolfShade is an unknown quantity at this point
I assume (since you did not provide it) that you are running "showMyDiv()" on page load?
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
WolfShade is offline   Reply With Quote
Old 07-23-2012, 09:32 PM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,162
Thanks: 59
Thanked 3,992 Times in 3,961 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
If you do it as you show, then the <div> will appear briefly and then get hidden.

Wouldn't it be better to *START* with it hidden and then only show it if the URL does *not* contain "wallpaper"??

If so, it's easy:
Code:
<html>
<body>
...
<div id="hide" style="display: none;">....</div>
...
<script type="text/javascript">
if (! /wallpapers/i.test(location.href) ) { 
    document.getElementById("hide").style.display="block";
}
</script>
</body>
</html>
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 07-24-2012, 08:13 AM   PM User | #4
mark1ra
New to the CF scene

 
Join Date: Jul 2012
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
mark1ra is an unknown quantity at this point
As I said I have problem with urls, so as you can see 2 and 3 have the same word in it:
1. www.mywebsite.com
2. www.mywebsite.com/wallpapers/show/...
3. www.mywebsite.com/wallpapers/browse_by_size/...
4. www.mywebsite.com/categories/show/...
PROBLEM: I need to show DIV only in 2-url, which leads to wallpaper, while 3-url leads to wallpaper category.
mark1ra is offline   Reply With Quote
Old 07-24-2012, 08:26 AM   PM User | #5
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Code:
if (/(wallpapers\/show)/i.test(url)) { // the words appears in the url
Do please read the posting guidelines regarding silly thread titles. The thread title is supposed to help people who have a similar problem in future. Yours is useless for this purpose. Everyone posting here wants help with his Javascript code. You can (and should) edit it to make it more meaningful.



"A psychiatrist asks a lot of expensive questions that your wife asks for nothing." – Joey Adams
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

Last edited by Philip M; 07-24-2012 at 08:29 AM..
Philip M is online now   Reply With Quote
Users who have thanked Philip M for this post:
mark1ra (07-24-2012)
Old 07-24-2012, 08:52 AM   PM User | #6
mark1ra
New to the CF scene

 
Join Date: Jul 2012
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
mark1ra is an unknown quantity at this point
Quote:
Originally Posted by Philip M View Post
Code:
if (/(wallpapers\/show)/i.test(url)) { // the words appears in the url
Do please read the posting guidelines regarding silly thread titles. The thread title is supposed to help people who have a similar problem in future. Yours is useless for this purpose. Everyone posting here wants help with his Javascript code. You can (and should) edit it to make it more meaningful.



"A psychiatrist asks a lot of expensive questions that your wife asks for nothing." – Joey Adams
Thanks, next time I will write it properly.
mark1ra is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:51 PM.


Advertisement
Log in to turn off these ads.