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
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);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.