Object type.
Posted: Tue Feb 13, 2007 2:00 pm
How would I check if this is referring to an image object?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
if (this.tagName.toUpperCase() == "IMG")
Code: Select all
if (navigator.userAgent.indexOf("MSIE 6" || "MSIE 5") != -1)
{
jQuery.fn.pngies = function () {
if (this.tagName == "img")
{
if (this.src.indexOf("x.gif") == -1)
{
$(this).css({ filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.src + "', sizingMethod='image')" });
this.src = "x.gif"
}
else
{
}
}
else
{
$("img").each(function(i) {
if ($(this).attr("class") != "nopngies")
{
$(this).load(function(e) {
e = e || window.event;
$(e.target).pngies();
});
if (this.src.substr(this.src.length - 4, 4).toUpperCase() == ".PNG")
{
$(this).css({ height: $(this).height(), width: $(this).width(), filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.src + "', sizingMethod='scale')" });
this.src = "x.gif";
}
}
});
}
}
$(document).ready(function () {
$().pngies();
});
};
Code: Select all
if (navigator.userAgent.indexOf("MSIE 6" || "MSIE 5") != -1)
{
jQuery.fn.pngies = function () {
if (this equals an image object goes here)
{
if (this.src.indexOf("x.gif") == -1)
{
$(this).css({ filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.src + "', sizingMethod='image')" });
this.src = "x.gif"
}
else
{
}
}
else
{
$("img").each(function(i) {
if ($(this).attr("class") != "nopngies")
{
$(this).load(function(e) {
e = e || window.event;
$(e.target).pngies();
});
if (this.src.substr(this.src.length - 4, 4).toUpperCase() == ".PNG")
{
$(this).css({ height: $(this).height(), width: $(this).width(), filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.src + "', sizingMethod='scale')" });
this.src = "x.gif";
}
}
});
}
}
$(document).ready(function () {
$().pngies();
});
};
Code: Select all
$(function(){
// if it's not IE, get out
if(!$.browser.msie) return true;
$('img').filter(function(index){
// code aborted
if($(this).attr("class")=="nopngies") return false;
// get the height, width and src before the image is gone
h = $(this).height();
w = $(this).width();
src = $(this).attr('src');
// if she's a png, keep the element
if($(this).attr('src').search(/png$/i) >= '0') return true;
// set the height, width, 'filter' and blank gif src
}).height(h).width(w).css('filter',"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')").attr('src','blank.gif');
});
It's good!Kieran Huggins wrote:how about:Code: Select all
$(function(){ // if it's not IE, get out if(!$.browser.msie) return true; $('img').filter(function(index){ // code aborted if($(this).attr("class")=="nopngies") return false; // get the height, width and src before the image is gone h = $(this).height(); w = $(this).width(); src = $(this).attr('src'); // if she's a png, keep the element if($(this).attr('src').search(/png$/i) >= '0') return true; // set the height, width, 'filter' and blank gif src }).height(h).width(w).css('filter',"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')").attr('src','blank.gif'); });