georgeocrawford
Technical User
Hi,
I'm using a flash animation to trigger a function called change_style on my page. The function loads a new style sheet and causes the page to change visually.
I'm stuck on the best way to approach the syntax for this. I want to cater for as many browsers as possible. I have learnt a bit about the different DOM types I'll have to deal with, but my knowledge of Javascript is very very basic and I can't quite make the function work!
The page initially contains this CSS link:
Here's what I want to do:
Now this doesn't work in Opera 6 for the Mac, which means that some browsers are falling through the function. Opera answers 'yes' to
but then fails to attatch the new CSS. This is why I want to have the page redirect option at each stage of the function.
How do I test if
or
have worked or not? I tried
etc. but it didn't work.
Thanks for any help!
______________________
George
I'm using a flash animation to trigger a function called change_style on my page. The function loads a new style sheet and causes the page to change visually.
I'm stuck on the best way to approach the syntax for this. I want to cater for as many browsers as possible. I have learnt a bit about the different DOM types I'll have to deal with, but my knowledge of Javascript is very very basic and I can't quite make the function work!
The page initially contains this CSS link:
Code:
<link id="style" rel="stylesheet" href="style.css" type="text/css">
Here's what I want to do:
Code:
If DOM is the old one {
use document.createStyleSheet to change the CSS
}
Else If DOM is the new one {
use document.getElementById('style').href to change the CSS
}
Else redirect the browser to a completely new page[code]
Even better than this would be:
[code]If DOM is the old one {
use document.createStyleSheet to change the CSS
If it worked {do nothing}
Else {redirect the browser to a completely new page}
}
Else If DOM is the new one {
use document.getElementById('style').href to change the CSS
If it worked {do nothing}
Else {redirect the browser to a completely new page}
}
Else redirect the browser to a completely new page[code]
And here is what I've done so far:
[code]function change_style() {
if (document.all) {
document.createStyleSheet('style2.css');
}
else if (document.getElementById) {
document.getElementById('style').href ='style2.css';
}
else {
window.location="[URL unfurl="true"]http://www.therealeubo.org.uk/index.html";[/URL]
}
}
Now this doesn't work in Opera 6 for the Mac, which means that some browsers are falling through the function. Opera answers 'yes' to
Code:
if (document.all)
How do I test if
Code:
document.createStyleSheet('style2.css');
Code:
document.getElementById('style').href ='style2.css';
Code:
if (!document.createStyleSheet('style2.css')) {window.location="[URL unfurl="true"]http://www.therealeubo.org.uk/index.html";}[/URL]
Thanks for any help!
______________________
George