...

View Full Version : Need help with javascript code



mark1ra
07-23-2012, 07:52 PM
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:

<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>

WolfShade
07-23-2012, 08:15 PM
I assume (since you did not provide it) that you are running "showMyDiv()" on page load?

Old Pedant
07-23-2012, 10:32 PM
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:


<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>

mark1ra
07-24-2012, 09:13 AM
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.

Philip M
07-24-2012, 09:26 AM
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

mark1ra
07-24-2012, 09:52 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum