Welcome Guest [Log In] [Register]
Search Members Calendar | Rules ZB Code Index IF Code Index
ZBCode
  • Navigation
  • ZBCode
  • Coding Support
  • Code University
  • Index Only
Hey, welcome to ZBCode, the premier coding forum for ZB. Here you fill find some of the best Invisionfree and Zetaboards Codes on the network! Unfortunately, you're sorta hovering around in guest mode at the moment; why not join in on the fun? Register an account and you can start accessing the wealth of resources we have available here. Enjoy your stay at ZBCode, and remember to tell all your friends about us; the more members, the more codes available. ;)

Interested in joining? Click here.


If you are already a member of ZBCode, feel free to login right here:

Username:   Password:
Locked Topic
Index Only
Tweet Topic Started: Apr 21 2009, 02:59 AM (239 Views)
PD.Phoenix Apr 21 2009, 02:59 AM Post #1
Member Avatar
Kokuhyou no Tentei

Posts:
326
Group:
Member
Member
#602
Joined:
Aug 15, 2008
Coding language
HTML/CSS
How do I make a code only work on the index?

Yeah, i've got the code to work, but it works everywhere. And I only want it to work on the index.

Thanx
Phoenix Designz is now open
Looking for staff and classers PM me here or on PD if interested.

Want to win some easy money? Enter Phoenix Designz tournaments. Learn more here ->> click


Posted Image
| My dA | Vote PD Top 100 |
Offline Profile Goto Top
 
Reid Apr 21 2009, 08:19 AM Post #2
Member Avatar
What? The land of the free? Whoever told you that was your enemy.

Posts:
1,790
Group:
Distinguished Coder
Member
#148
Joined:
Jul 20, 2008
Quote:
 
if (location.href.indexOf("/index")!=-1) {
CODE HERE
}
edit: and I feel the need to note the if statement and something about jQuery.

in jQuery if you're using $(document).ready() or $(function(){}) [the shorthand way] then the if statement needs to go inside.

For example, say we have the code:
Quote:
 
$(function(){alert('This is the index!')})
and we want it to work only on the index; we'd put
Quote:
 
$(function() { if (location.href.indexOf("/index")!=-1) { alert('This is the index!') }});
Just an extra thing I thought I'd mention.
Edited by Reid, Apr 21 2009, 08:28 AM.
The Resource Board
Offline Profile Goto Top
 
PD.Phoenix Apr 21 2009, 04:26 PM Post #3
Member Avatar
Kokuhyou no Tentei

Posts:
326
Group:
Member
Member
#602
Joined:
Aug 15, 2008
Coding language
HTML/CSS
Thanx

Here's what I wanted it for lol
http://zbcode.com/topic/1537704/
Phoenix Designz is now open
Looking for staff and classers PM me here or on PD if interested.

Want to win some easy money? Enter Phoenix Designz tournaments. Learn more here ->> click


Posted Image
| My dA | Vote PD Top 100 |
Offline Profile Goto Top
 
Vitality Apr 21 2009, 10:27 PM Post #4
Member Avatar
Tabula Rasa

Posts:
784
Group:
Former Staff
Member
#320
Joined:
Jul 26, 2008
Here is another way to do it (Not that Reid's is bad or worse than this)
Code: HTML
 
if(location.href.match('index/')){
//Code
}
To get specific you could use some RegExp in the .match() to match your address more specifically, but the quotes work perfectly fine.
Offline Profile Goto Top
 
Reid Apr 21 2009, 10:34 PM Post #5
Member Avatar
What? The land of the free? Whoever told you that was your enemy.

Posts:
1,790
Group:
Distinguished Coder
Member
#148
Joined:
Jul 20, 2008
Vitality
Apr 21 2009, 10:27 PM
Here is another way to do it (Not that Reid's is bad or worse than this)
Code: HTML
 
if(location.href.match('index/')){
//Code
}
To get specific you could use some RegExp in the .match() to match your address more specifically, but the quotes work perfectly fine.
Yep - .indexOf() is faster though, and I'm all about speed. :D

(although it's only milliseconds, so I'm not overly concerned about it)
The Resource Board
Offline Profile Goto Top
 
PD.Phoenix Apr 22 2009, 06:02 PM Post #6
Member Avatar
Kokuhyou no Tentei

Posts:
326
Group:
Member
Member
#602
Joined:
Aug 15, 2008
Coding language
HTML/CSS
Ok.. I've got another code that I can get to work on normal webpages, but I'm not too good with ZB and I can't get it to show up on a ZB forum

PM me if you think you can help, don't wanna post it yet.
Edited by PD.Phoenix, Apr 22 2009, 06:05 PM.
Phoenix Designz is now open
Looking for staff and classers PM me here or on PD if interested.

Want to win some easy money? Enter Phoenix Designz tournaments. Learn more here ->> click


Posted Image
| My dA | Vote PD Top 100 |
Offline Profile Goto Top
 
Reid Apr 22 2009, 06:04 PM Post #7
Member Avatar
What? The land of the free? Whoever told you that was your enemy.

Posts:
1,790
Group:
Distinguished Coder
Member
#148
Joined:
Jul 20, 2008
And the code is...?
The Resource Board
Offline Profile Goto Top
 
PD.Phoenix Apr 22 2009, 06:08 PM Post #8
Member Avatar
Kokuhyou no Tentei

Posts:
326
Group:
Member
Member
#602
Joined:
Aug 15, 2008
Coding language
HTML/CSS
Edited my last post

"PM me if you think you can help, don't wanna post it yet. "
Phoenix Designz is now open
Looking for staff and classers PM me here or on PD if interested.

Want to win some easy money? Enter Phoenix Designz tournaments. Learn more here ->> click


Posted Image
| My dA | Vote PD Top 100 |
Offline Profile Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Code University · Next Topic »
Locked Topic

Track Topic · E-mail Topic Time: 7:48 PM Jul 10
Hosted for free by ZetaBoards · Privacy Policy