Jump to content

Display PNG based on browser


Asheh

Recommended Posts

Ok peeps im so confused at javascript I dont know where to start, but anyways im trying to get somthing to display based on the type of browser so i have the following functor:

 

function displayPng(strId, strPath, intWidth, intHeight, strClass, strAlt) 
{	
var pngNormal = false;
if ((browser.isIE55 || browser.isIE6up) && browser.isWin32) {
	pngNormal = false;
// else, if the browser can display PNGs normally, then do that
} else if ((browser.isGecko) || 
		   (browser.isIE5up && browser.isMac) || 
		   (browser.isOpera && browser.isWin && browser.versionMajor >= 6) || 
		   (browser.isOpera && browser.isUnix&& browser.versionMajor >= 6) || 
		   (browser.isOpera && browser.isMac && browser.versionMajor >= 5) || 
		   (browser.isOmniweb && browser.versionMinor >= 3.1) || 
		   (browser.isIcab && browser.versionMinor >= 1.9) || 
		   (browser.isWebtv) || 
		   (browser.isDreamcast)) 
{
	pngNormal = true;
}

if (pngNormal == false) 
{
	alert("nonormal");
  document.write('<div style="height:'+intHeight+
				 'px;width:'+intWidth+
				 'px; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+strPath+'.png\', sizingMethod=\'scale\')"  id="'+strId+'" class="'+strClass+'"></div>');
} 
else if (pngNormal) 
{
alert("normal");
  document.write('<img src="'+strPath+'.png" width="'+intWidth+'" height="'+intHeight+'" name="'+strId+'" border="0" class="'+strClass+'" alt="'+strAlt+'" />');
} 	
}

 

My first guess was that "alert" is no longer supported by any browsers, but then i tried to actually call the function in code like this:

 

<SCRIPT language="JavaScript"> 
<!--hide  
	displayPng('','','','','','','');
//--> 
</SCRIPT>

 

 

I checked the outputted html but it doesnt display anything but that?

 

Im so confused, how can i call a function inline so that it displays an image based on the browser??

 

Cheers  ???

 

Link to comment
https://forums.phpfreaks.com/topic/45530-display-png-based-on-browser/
Share on other sites

Here is a small code to check which browser the user uses (from the NoGray Javascript Library)

// checking if the browser is Opera
var is_Opera = (window.navigator.userAgent.search("Opera") != -1);

// checking if the browser is IE
var is_IE = ((window.navigator.userAgent.search("MSIE") != -1) && !is_Opera);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.