BoltZ Posted October 27, 2008 Share Posted October 27, 2008 <script type="text/javascript"> var browserName=navigator.appName; if (browserName=="Netscape")//Mozilla Firefox Chrome { <? echo '<link rel="stylesheet" type="text/css" href="stylesheet.css" />'; ?> } else { if (browserName=="Microsoft Internet Explorer") { <? echo '<link rel="stylesheet" type="text/css" href="iestyle.css" />'; ?> } else //Opera Safari { <? echo '<link rel="stylesheet" type="text/css" href="stylesheet.css" />'; ?> } } </script> I have this code to find the browser then echo the stylesheet. and this code works fine in the navigator part sense but the error i am sure is that i am not sure if i am allowed to call php in JS. anyone know a way to make it display the stylesheet according to the browser since i cant echo php? Quote Link to comment https://forums.phpfreaks.com/topic/130354-solved-error-with-stylesheet-and-php-in-js/ Share on other sites More sharing options...
F1Fan Posted October 27, 2008 Share Posted October 27, 2008 JS is client-side, and PHP is server-side. If you view your source, that's exactly what JS will be running. "echo" is PHP code, and it's gonna echo whether the JS wants it to or not. Quote Link to comment https://forums.phpfreaks.com/topic/130354-solved-error-with-stylesheet-and-php-in-js/#findComment-676137 Share on other sites More sharing options...
BoltZ Posted October 27, 2008 Author Share Posted October 27, 2008 But i tried that code in a offline status with an alert instead of that echo stuff and it worked fine. Never mind anymore i decided to simply use get_browser function from php since you cant disable php Quote Link to comment https://forums.phpfreaks.com/topic/130354-solved-error-with-stylesheet-and-php-in-js/#findComment-676155 Share on other sites More sharing options...
F1Fan Posted October 28, 2008 Share Posted October 28, 2008 Yeah. "alert" is JavaScript, and "echo" is PHP. Therefore, using "alert" in JS would work, and using "echo" would not. Quote Link to comment https://forums.phpfreaks.com/topic/130354-solved-error-with-stylesheet-and-php-in-js/#findComment-676562 Share on other sites More sharing options...
BoltZ Posted October 28, 2008 Author Share Posted October 28, 2008 Yea i decided in the end to make it so i use the get_browser functionn in php since people can't disable PHP Quote Link to comment https://forums.phpfreaks.com/topic/130354-solved-error-with-stylesheet-and-php-in-js/#findComment-677018 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.