Forum Moderators: coopster
1. Testing for NS4 browsers is easy with Javascript using "if (document.layers) {...whatever...}". Is it possible to use the same test in php?
2. Is it possible to include Javascript within a php include?
For example:
<?php require("../foobar.inc");?>
where foobar.inc is:
xhtml and text...
<script type="text/javascript">
if (document.layers)
{document.write("HI THERE");}
</script>
more xhtml and text...
Can this be made to work?
Any help appreciated
Harry
2. You include js with the script src="something.js" just like always. Keep in mind that php is run on the server side before the page is served. PHP builds and serves a regular old html document. There isn't always a need to convert your js. If your js works well why change it?
Best tool for each job, just because I use php doesn't mean I stop using html, css, js etc. I just have one more tool at my disposal which happens to be much more powerful than those others I listed. ;)
// simple browser detection in php
$whichBrowser = $_SERVER['HTTP_USER_AGENT'];
if (stristr($whichBrowser, "Opera"))
{
$browser = 'opera';
}
elseif (stristr($whichBrowser, "MSIE 4"))
{
$browser = 'msie4';
}
elseif (stristr($whichBrowser, "MSIE"))
{
$browser = 'msie5x;
}
elseif ((stristr($whichBrowser, "Konqueror")) ¦¦ (stristr($whichBrowser, "Safari")))
{
$browser = 'safari';
}
elseif (stristr($whichBrowser, "Gecko"))
{
$browser = 'gecko';
}
elseif (stristr($whichBrowser, "Mozilla/4"))
{
$browser = 'ns4';
}
else
{
$browser = 'unknown';
}
That is the way I identify all the other browsers, but I had overlooked the point that by excluding the other contenders the only remaining Mozilla/4 had to be NS4.
The only point I'm concerned about is Mac browsers about which I know nothing. Are there any non-Windows browsers defined as Mozilla/4?
Although I suppose I could cover that by also testing for the presence of "Win".
Harry
if ( stristr($whichBrowser, "Mac") ){
$os = 'mac';
}
elseif ( stristr($whichBrowser, "Win") ){
$os = 'win';
}
else {
$os = 'other';
}
so if you want to specify browsers:
if ( ($browser == 'ie'){
if ( $os == 'mac' ){
$browser = 'iemac';
}
elseif ( $os == 'win' ){
$browser = 'iewin';
}
}
or something to that affect. I haven't seen any significant rendering differences on Mozilla between os's, although Opera mac is very different from opera windows, but there are virtually no opera macs out there so it's not really worth worrying about.