Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
transparent png script in IE
Old 08-02-2006, 08:45 PM transparent png script in IE
carterdea's Avatar
Ultra Talker

Posts: 353
Location: Arizona
Trades: 0
I used a script to make transparent png's work in IE but it didn't work! Here's the link.

If you know any scripts that work, or can fix my existing script, please tell me!

Thanks

carter
carterdea is offline
Reply With Quote
View Public Profile Visit carterdea's homepage!
 
 
Register now for full access!
Old 08-07-2006, 02:46 PM Re: transparent png script in IE
Ultra Talker

Posts: 256
Location: Auckland, New Zealand
Trades: 0
This script should work. I've rewritten it slightly:

Here it is:

fixpng.js saved in the same directory as the page using it.
Code:
var arVersion = navigator.appVersion.split('MSIE');
    var version = parseFloat(arVersion[1]);
    if(version >= 5.5 && document.body.filters)
    {
      for(var i = 0, n = document.images.length; i < n; i++)
      {
        var img = document.images[i];
        var imgName = img.src.toUpperCase();
        if(imgName.substring(imgName.length - 3, imgName.length))
        {
          var imgID = (img.id) ? 'id="' + img.id + '" ' : '';
          var imgClass = (img.className) ? 'class="' + img.className + '" ' : '';
          var imgTitle = (img.title) ? 'title="' + img.title + '" ' : 'title="' + img.alt + '" ';
          var imgStyle = 'display: inline-block;' + img.style.cssText;
          if(img.align == 'left') imgStyle = 'float:left;' + imgStyle;
          if(img.align == 'right') imgStyle = 'float:right;' + imgStyle;
          if(img.parentElement.href) imgStyle = 'cursor: hand;' + imgStyle;
          var strNewHTML = '<span ' + imgID + imgClass + imgTitle + 'style="' + 'width:' + img.width + 'px; height: ' + img.height + 'px;' + imgStyle + ';' + 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + img.src + '", sizingMethond="scale");"></span>';
          img.outerHTML = strNewHTML;
          i = i - 1;
        }
      }
    }
Tested in IE6 and works.

To use it you insert this line inside your <head> element.

Code:
<!--[if lt IE 7]><script type="text/javascript" defer="true" src="fixpng.js"></script><![endif]-->
You must make sure that your images have the correct src, alt, width and height attribute. If not it could fail, it also does not work for background images.

For Linux users using IE under wine, it will throw an alert because the DirectX class is not avaliable, nor did I hear any plans of it. If you want to be sneaky, then change the type="text/css", it is only affecting IE after all and IE usually uses it's own mime detection technique rather than relying on what authors say it is.

I'm not sure whether this is a quicker option than just loading a transparent gif, but if you need alpha transparency, then this is the only way you could do such a thing.

Cheers,

MC
__________________
#------------------------------signature---------------------------------------------------------------------------------#
Quote:
I am well recognised for what I don't do than what I do. Chores are just one of those things.

Last edited by mastercomputers; 08-07-2006 at 03:38 PM..
mastercomputers is offline
Reply With Quote
View Public Profile Visit mastercomputers's homepage!
 
Old 08-07-2006, 04:18 PM Re: transparent png script in IE
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
Code:
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale src='(your image here)');
It's not valid CSS, but it does work every time. So if you're really worried about it, I'd suggest putting this in its own CSS file that you know is invalid and that you don't care about and then putting the valid CSS separate.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 08-07-2006, 10:33 PM Re: transparent png script in IE
carterdea's Avatar
Ultra Talker

Posts: 353
Location: Arizona
Trades: 0
thanks soooo much
carterdea is offline
Reply With Quote
View Public Profile Visit carterdea's homepage!
 
Reply     « Reply to transparent png script in IE
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13766 seconds with 12 queries