Welcome Guest [Log In] [Register]
Search Members Calendar | Rules ZB Code Index IF Code Index
ZBCode
  • Navigation
  • ZBCode
  • Coding Resources
  • Code Requests
  • Completed Requests
  • [Completed] [ZB] Multiple Stylesheets
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
[Completed] [ZB] Multiple Stylesheets
Tweet Topic Started: Sep 19 2009, 08:25 PM (275 Views)
Ava Sep 19 2009, 08:25 PM Post #1
Member Avatar
A.V.A

Posts:
276
Group:
Member
Member
#3,254
Joined:
Jun 25, 2009
Hey.

I was wondering if there's a way to add more stylesheets like : <link rel="stylesheet" type="text/css" href=".css" /> : to my board, but so that it only works on specific pages of my board. Is there a way to somehow enter it before ANY of the page content loads, and only have it active on certain pages? (FYI : These certain pages are webpages! However, I've tried posting it in the HTML section of the webpage editor, and it does not load before some of the page content, which tends to ruin the flow of the webpage.)

Note : I would like the specific elements defined in the new stylesheets to overwrite the similar ones in the original.

Thanks in advance.

Ava
Edited by Ava, Sep 19 2009, 08:29 PM.
Posted Image
Offline Profile Goto Top
 
Firestrife2 Sep 19 2009, 08:41 PM Post #2
Member Avatar


Posts:
159
Group:
Dedicated
Member
#2,094
Joined:
Jan 21, 2009
See if this goes faster, put in "Javascripts" which is at the very top. I'm not 100% sure it will work, so test it out for me eh?

Code
 
if(location.href.match(/pages\/\PAGENAME/i)){
document.write('<link rel="stylesheet" type="text/css" href="STYLESHEETNAME.css" />');
}


Just edit the red and blue.
Posted Image

Posted Image
Offline Profile Goto Top
 
Ava Sep 19 2009, 09:46 PM Post #3
Member Avatar
A.V.A

Posts:
276
Group:
Member
Member
#3,254
Joined:
Jun 25, 2009
Works like a charm :)
Is there a way for me to add multiple stylesheets to different pages with this script, without having to paste it 13 times (that's how many pages I need to assign stylesheets to)?
If it helps at all : It's the same stylesheet I'd like to add to all 13 pages.
Edited by Ava, Sep 19 2009, 11:49 PM.
Posted Image
Offline Profile Goto Top
 
Gorgor Sep 20 2009, 05:26 AM Post #4
Hello

Posts:
1,187
Group:
Former Staff
Member
#2,728
Joined:
Apr 2, 2009
Coding language
PHP
Well first off, you don't need the slashes as that indicates a RegExp, quotes are better. For multiple pages, use
Code:
 
if(location.href.match("PAGE URL") || location.href.match("PAGE URL2") || location.href.match("PAGE URL3") || ect...){
document.write('<link rel="stylesheet" type="text/css" href="STYLESHEETNAME.css" />');
}
Offline Profile Goto Top
 
Ava Sep 20 2009, 06:07 AM Post #5
Member Avatar
A.V.A

Posts:
276
Group:
Member
Member
#3,254
Joined:
Jun 25, 2009
Gorgor

I've tried your version of this code, and replaced the "PAGE URL" text with the page URL's, and it does not work. I have 13 of these pages. Perhaps that is too many to work with this code.

I'm positive my css works, granted it works with Firestrife's code, however.

Ava
Edited by Ava, Sep 20 2009, 06:09 AM.
Posted Image
Offline Profile Goto Top
 
Gorgor Sep 20 2009, 06:36 AM Post #6
Hello

Posts:
1,187
Group:
Former Staff
Member
#2,728
Joined:
Apr 2, 2009
Coding language
PHP
Can I see the exact code you're using please?

at the end, the code should look like this...
Code:
 
...location.href.match("PAGE URL 13")){
With two parenthesis', not one.
Edited by Gorgor, Sep 20 2009, 06:37 AM.
Offline Profile Goto Top
 
Firestrife2 Sep 21 2009, 05:41 AM Post #7
Member Avatar


Posts:
159
Group:
Dedicated
Member
#2,094
Joined:
Jan 21, 2009
When using quotes, I thought you had to enter the whole URL most of the time xD?

As I said, I always prefer regexp.

You could also do the same that way.

if(location.href.match(/pages\/\PAGENAME/i) || location.href.match(/pages\/\PAGE2NAME/i)){

:3.
Posted Image

Posted Image
Offline Profile Goto Top
 
Cory Sep 21 2009, 02:15 PM Post #8


Posts:
12
Group:
Member
Member
#106
Joined:
Jul 18, 2008
Coding language
HTML/CSS
There's also this if you don't wish to use JavaScript.
Posted Image
Offline Profile Goto Top
 
Ava Sep 23 2009, 12:03 PM Post #9
Member Avatar
A.V.A

Posts:
276
Group:
Member
Member
#3,254
Joined:
Jun 25, 2009
This request is complete. Thanks!
Posted Image
Offline Profile Goto Top
 
Reid Sep 23 2009, 12:29 PM Post #10
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
You're welcome.
See? We can read thoughts too. ;)

Your request has been completed, and we're moving it to the correct forum. We hope it works for you; if it doesn't, feel free to post another request topic in the requests forum. Just remember: read the rules first!

Thanks,
The ZBCode Staff
The Resource Board
Offline Profile Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Completed Requests · Next Topic »
Locked Topic

Track Topic · E-mail Topic Time: 2:27 PM Jul 11
Hosted for free by ZetaBoards · Privacy Policy