/    Sign up×
Community /Pin to ProfileBookmark

writing tags with php…

Hi !!!
I’m sure this is a basic one, but…
Let me explain it all.
On my website, I have a css switcher ( the one from Paul Sowden, ALA ) in javascript. So far, everything is fine.
BUT : my website uses an iframe. And in the iframe, the pages used to get their css from the parent. ( in the parent page, I defined :

[code=php]var styleSheet=’bttf.css’;[/code]

and in the child pages :

[code=php]
<script language=”JavaScript1.2″>
document.write(‘<LINK REL=stylesheet HREF=”‘+parent.styleSheet+'” TYPE=”text/css”>’)
</script>
[/code]

It worked really fine.

My problem is now that the stylesheet changes in the parent page, with this css switcher.
So I’d like to know if it’s possible to write seomthing in php that would write this variable accodring to which style sheet is being used. ( I also have a script which would need to be written according to the style sheet in use ).
How can I do this in php ? How can I detect which style sheet is being used ?

What I have in the header of the parent page :

[code=php]
<link rel=”stylesheet” type=”text/css” href=”css1.css” title=”blanche” />
<link rel=”alternate stylesheet” type=”text/css” href=”css2.css” title=”violet” />

<script type=”text/javascript”
src=”styleswitcher.js”></script>
[/code]

the style switcher :

[code=php]
function setActiveStyleSheet(title) {
var i, a, main;
for(i=0; (a = document.getElementsByTagName(“link”)[i]); i++) {
if(a.getAttribute(“rel”).indexOf(“style”) != -1 && a.getAttribute(“title”)) {
a.disabled = true;
if(a.getAttribute(“title”) == title) a.disabled = false;
}
}
}

function getActiveStyleSheet() {
var i, a;
for(i=0; (a = document.getElementsByTagName(“link”)[i]); i++) {
if(a.getAttribute(“rel”).indexOf(“style”) != -1 && a.getAttribute(“title”) && !a.disabled) return a.getAttribute(“title”);
}
return null;
}

function getPreferredStyleSheet() {
var i, a;
for(i=0; (a = document.getElementsByTagName(“link”)[i]); i++) {
if(a.getAttribute(“rel”).indexOf(“style”) != -1
&& a.getAttribute(“rel”).indexOf(“alt”) == -1
&& a.getAttribute(“title”)
) return a.getAttribute(“title”);
}
return null;
}

function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = “; expires=”+date.toGMTString();
}
else expires = “”;
document.cookie = name+”=”+value+expires+”; path=/”;
}

function readCookie(name) {
var nameEQ = name + “=”;
var ca = document.cookie.split(‘;’);
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==’ ‘) c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}

window.onload = function(e) {
var cookie = readCookie(“style”);
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
}

window.onunload = function(e) {
var title = getActiveStyleSheet();
createCookie(“style”, title, 365);
}

var cookie = readCookie(“style”);
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
[/code]

and then, again in the parent page, the links to call a css or the other.

[code=php]
<div id=”version”><a href=”#” onclick=”setActiveStyleSheet(‘blanche’); return false;”>change style to white</a>
<a href=”#” onclick=”setActiveStyleSheet(‘violet’); return false;”>change style to violet</a>
</div>
[/code]

I’ll use five css, but for the moment, I tested it with 2 only…

If you could give me a hand, I would be eternally gratefull. I posted in the js forum too, but I guess the solution will be part php and part js…
Thanks for all suggestions !!!
I really want to keep the child pages with only that

[code=php]
<script language=”JavaScript1.2″>
document.write(‘<LINK REL=stylesheet HREF=”‘+parent.styleSheet+'” TYPE=”text/css”>’)
</script>
[/code]

in the <head>…

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@96turnerriApr 16.2005 — if i understand you correctly you cannot detect what stylesheet is being used by a browser in PHP, the only thing i would suggest is use a php stylesheet changer not a javascript one
Copy linkTweet thisAlerts:
@Ness_du_FratauthorApr 17.2005 — OK, I might have an idea on how to achieve what I'm doing... I'll post later to see if it worked... ?
×

Success!

Help @Ness_du_Frat spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...