Javascript sniff and PHP
Internet Explorer, javascript, PHP December 13th, 2007
I think that most of the web developers at some point got a issue with a older version of MSIE and have to figure out a way to work around the issue either by re-doing it, creating another CSS or manipulating it with javascript.
I got a issue like this and with a nice little hack with PHP and Javascript I could easily fix the issue.
The issue was a iframe that needed to be resized at IE 6 at the resolution of 800×600. Who would use a browser so old with a resolution like this? Believe me, you would be impressed.
Anyway the script was basicly sniffing the browser info with Javascript and PHP at same time. Unfortunally Javascript does not give a precise information about the browser version in IE 6 and 7, returning version = 4, but PHP does.
At the end this is how the script became:
<script language=”javascript” type=”text/javascript”>
var browser = navigator.appName; /* Getting the Browser Name */
var b_version = navigator.appVersion; /* Getting the Browser Version - not reliable */
var version = parseFloat(b_version); /* Transforming the Browser Version Information to a number */
<?php
/* PHP hack for version on Javascript */
$info = explode(’;',$_SERVER[’HTTP_USER_AGENT’])
?>
var info = ‘<?php echo trim($info[1]); ?>’;
var iframe = document.getElementById(’iFrame’); /* Iframe that will be modified */
var wscreen = parseFloat(screen.width); /* Getting the size of the screen */
if(info == ‘MSIE 6.0′ && wscreen < 900)
{
iframe.style.height = 325; /* Resizing the iframe to a size that will hold all information */
}
</script>
At first I was using the 3 first vars to do the same thing as I’m doing with the var info = ‘<?php echo trim($info[1]) ?>’; and time to time it was giving errors, so this small trick became very handy.
Posts
Leave a Comment
You must be logged in to post a comment.