Jonas Posted October 9, 2005 Share Posted October 9, 2005 Ok, so I've used simple scripts for some time, and now I'm making a site for my dad's company. However, due to Internet Explorer and Mozilla Firefox's showing css differently from the browser I'm using (Opera), I'm not managing to show the site the way I want.http://www.w3schools.com/js/tryit.asp?file...js_crossbrowserSo, after reading that, and also having searched around a bit on the web, is there any way of redirecting to different browsers. My biggest problem so far is that Opera disguises itself as Internet Explorer when "navigator.appname" is called through a function. Also, I found this script:http://www.cssplay.co.uk/archive/themes_v2.json this site:http://www.cssplay.co.uk/and it gave me the idea of just switching stylesheet based on browser. I managed to make a script where you could choose stylesheet through <select> and <option>. But that doesn't work in IE for some reason, and besides I don't want to have the reader change stylesheet for every new link or update. Like I said, ideally the ideal stylesheet should be chosen based on browser. SO, is there anyway of doing this? Any ideas? Could navigator.userAgent be an idea? Can anyone good at javascript help me with this?Any help highly appreciated... Link to comment Share on other sites More sharing options...
Chocolate570 Posted October 9, 2005 Share Posted October 9, 2005 You could send the user to a different page depending on their browser....each page with a different style sheet. Using window.location. And about opera disguising itself; i think that there are more intricate navigator.x functions that will return the fact that it's opera. Yes, i know, i really stink. Link to comment Share on other sites More sharing options...
Webworldx Posted October 9, 2005 Share Posted October 9, 2005 userAgent is a nicer one, Opera declares itself through that. A combination of appName and userAgent should provide you with enough to browser sniff. It's always good to check whether the function you're trying to use is directly supported though - i.e:if( document.thisThing() ){} Link to comment Share on other sites More sharing options...
Jonas Posted October 10, 2005 Author Share Posted October 10, 2005 Ok, so it wasn't that hard after all... Â <script type="text/javascript"> Â var useragent = navigator.userAgent; Â var bName = (useragent.indexOf('Opera') > -1) ? 'Opera' : navigator.appName; Â if (bName == "Opera") { Â Â document.write('<link type="text/css" rel="stylesheet" href="opera.css" />') Â } Â else if (bName == "Netscape") { Â Â document.write('<link type="text/css" rel="stylesheet" href="netscape.css" />') Â } Â else { Â Â document.write('<link type="text/css" rel="stylesheet" href="microsoft.css" />') Â } Â </script> Link to comment Share on other sites More sharing options...
Chocolate570 Posted October 10, 2005 Share Posted October 10, 2005 Exactly. I stink. :)And good luck with the site Link to comment Share on other sites More sharing options...
Jonas Posted October 11, 2005 Author Share Posted October 11, 2005 Ok, so it wasn't that hard after all... Â <script type="text/javascript"> Â var useragent = navigator.userAgent; Â var bName = (useragent.indexOf('Opera') > -1) ? 'Opera' : navigator.appName; Â if (bName == "Opera") { Â Â document.write('<link type="text/css" rel="stylesheet" href="opera.css" />') Â } Â else if (bName == "Netscape") { Â Â document.write('<link type="text/css" rel="stylesheet" href="netscape.css" />') Â } Â else { Â Â document.write('<link type="text/css" rel="stylesheet" href="microsoft.css" />') Â } Â </script> <{POST_SNAPBACK}> LOL! With this new code I get validation error, saying <link> element is not allowed where it is. I just cheated using document.write('<'+'...') Now I just get a warning, but still valid xhtml 1.1... Link to comment Share on other sites More sharing options...
Webworldx Posted October 11, 2005 Share Posted October 11, 2005 I've had this too. I just end up throwing all javascripts into a .js file, solves it Link to comment Share on other sites More sharing options...
Jonas Posted October 11, 2005 Author Share Posted October 11, 2005 I've had this too. I just end up throwing all javascripts into a .js file, solves itYeah, tried that, but it didn't work for some reason. When I tried it (due to my choice of <link etc. />), it didn't write it into my document, and so no stylesheet was loaded. If it was redirect based on browser I suppose it would work, but with the script changing css file, I don't have to have three of each document... Link to comment Share on other sites More sharing options...
Chocolate570 Posted October 11, 2005 Share Posted October 11, 2005 "+-->QUOTE ("Skin Selector Javascript Code Thing ") Â <script type="text/javascript">Â var useragent = navigator.userAgent;Â var bName = (useragent.indexOf('Opera') > -1) ? 'Opera' : navigator.appName;Â if (bName == "Opera") {Â document.write('<link type="text/css" rel="stylesheet" href="opera.css" />')Â }Â else if (bName == "Netscape") {Â document.write('<link type="text/css" rel="stylesheet" href="netscape.css" />')Â }Â else {Â document.write('<link type="text/css" rel="stylesheet" href="microsoft.css" />')Â } </script>don't you have to escape the <'s?Also, did you take out the script tag?(for external hostign) Link to comment Share on other sites More sharing options...
Jonas Posted October 11, 2005 Author Share Posted October 11, 2005 "+-->QUOTE ("Skin Selector Javascript Code Thing ") Â <script type="text/javascript">Â var useragent = navigator.userAgent;Â var bName = (useragent.indexOf('Opera') > -1) ? 'Opera' : navigator.appName;Â if (bName == "Opera") {Â Â document.write('<link type="text/css" rel="stylesheet" href="opera.css" />')Â }Â else if (bName == "Netscape") {Â Â document.write('<link type="text/css" rel="stylesheet" href="netscape.css" />')Â }Â else {Â Â document.write('<link type="text/css" rel="stylesheet" href="microsoft.css" />')Â } </script>don't you have to escape the <'s?Also, did you take out the script tag?(for external hostign)<{POST_SNAPBACK}> I got a validation warning that I should escape the "<" with < yes, but if I do that it's not implemented as a tag like I want it to... :DAnd yes, removed the script tag. Give me some credit here... :(Dunno why it doesn't work... Link to comment Share on other sites More sharing options...
WiCkEdStYlZ` Posted October 11, 2005 Share Posted October 11, 2005 <script type="text/javascript"> var useragent = navigator.userAgent; var bName = (useragent.indexOf('Opera') > -1) ? 'Opera' : navigator.appName; if (bName == "Opera") { document.write('<link type=\"text\/css\" rel=\"stylesheet\" href=\"opera.css\" />') } else if (bName == "Netscape") { document.write('<link type=\"text\/css\" rel=\"stylesheet\" href=\"netscape.css\" />') } else { document.write('<link type=\"text\/css\" rel=\"stylesheet\" href=\"microsoft.css\" />') }</script> there ya go.. remember to backslash your quatation marks, forwardslahses, e.t.c. Link to comment Share on other sites More sharing options...
Chocolate570 Posted October 12, 2005 Share Posted October 12, 2005 What i meant. ^^To escape the thing is to backslash all quotes and stuff. Link to comment Share on other sites More sharing options...
WiCkEdStYlZ` Posted October 12, 2005 Share Posted October 12, 2005 ya, jus makin life easier n breakin info down... if they didnt know they had to escape html characters then they probably didnt know what it meant... so gave em the code n said what was diff bout code... < doesn't need to be backslashed either Link to comment Share on other sites More sharing options...
Chocolate570 Posted October 12, 2005 Share Posted October 12, 2005 I think you misunderstood. I wasn't flaming you. Thanks for making waht i said easier Link to comment Share on other sites More sharing options...
WiCkEdStYlZ` Posted October 12, 2005 Share Posted October 12, 2005 yep i didnt think u were.... n i wasnt flamin u either m8 lolz, sorry if it came out that way n no probs thx for makin that noticable to me lol Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now