GOING CRAZY... can't find the error in a few lines of code

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
maros174
Forum Newbie
Posts: 11
Joined: Tue Mar 02, 2010 7:23 am

GOING CRAZY... can't find the error in a few lines of code

Post by maros174 »

Code: Select all

if (navigator.userAgent.toLowerCase().indexOf('msie 6')!=-1){
              $("#pdfPopup img[@src$=png]").pngfix();
              $("#pdfPopup .sidebar ul").css({
                    background: "none",
                     filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+urlRoot+"/images/BKGmodelsBox_grad.png', sizingMethod='scale')"
               });
         }
This is a part of the larger .js code. It fixes .PNG images problem specific to IE6.
Everything works fine in Firefox, Opera, IE6 and Chrome.

The problem appears only in IE7 and IE8.
JavaScript stops executing somewhere after the second line, and the browser reports an error in .js file on that line...

Somebody please help....
maros174
Forum Newbie
Posts: 11
Joined: Tue Mar 02, 2010 7:23 am

Re: GOING CRAZY... can't find the error in a few lines of co

Post by maros174 »

I think this is the problem:

Code: Select all

navigator.userAgent.toLowerCase().indexOf('msie 6')!=-1
IE7 and IE8 just stop loading javascipt after that.
This is something new, everything was working fine until recently - I just noticed it today.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: GOING CRAZY... can't find the error in a few lines of co

Post by Eran »

If you're using jQuery, you might as well use its built in browser detection - http://api.jquery.com/jQuery.browser/
maros174
Forum Newbie
Posts: 11
Joined: Tue Mar 02, 2010 7:23 am

Re: GOING CRAZY... can't find the error in a few lines of co

Post by maros174 »

I'm not that good in this... That is way beyond my level of expertise...
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: GOING CRAZY... can't find the error in a few lines of co

Post by pickle »

pytrin wrote:If you're using jQuery, you might as well use its built in browser detection - http://api.jquery.com/jQuery.browser/
+1

In addition, install the developer tools for IE8 - it can give you more useful javascript errors.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
maros174
Forum Newbie
Posts: 11
Joined: Tue Mar 02, 2010 7:23 am

Re: GOING CRAZY... can't find the error in a few lines of co

Post by maros174 »

I looked elsewhere on the site. Other page that uses same solution to IE6 transparency problem also stopped working.

First it reported an error (on line 136), here on the first two lines:

Code: Select all

function ie6PngFix(){
    $(".content img[@src$=png]").pngfix();

    $(".sidebar ul").css({
        background: "none",
        filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+urlRoot+"/images/BKGmodelsBox_grad.png', sizingMethod='scale')"
    });
When I commented that part of the code it reported an error (on line 71), here on the second line:

Code: Select all

$(document).ready(function() {
    if (navigator.userAgent.toLowerCase().indexOf('msie 6')!=-1){ ie6PngFix(); }
    if (navigator.userAgent.toLowerCase().indexOf('msie 6')!=-1){ ie6HoverFix(); }
    else  { over_hover(".sidebar ul li"); }
    slideFeatures();
    modelFormPopupCheck(".modelsButt");
    $("#modelsNav li").click(function(){
        if ($(this).is(".on") || $(".modelContent").is(":animated") ) { return false; }
        $("#modelsNav li").removeClass("on");
        $(this).addClass("on");
        switchModelsContents($(this).prevAll().length)
    });
});
maros174
Forum Newbie
Posts: 11
Joined: Tue Mar 02, 2010 7:23 am

Re: GOING CRAZY... can't find the error in a few lines of co

Post by maros174 »

...
Ok, I've isolated the problem.

IE7 and IE8 report an error on this line in the function below:
$(".content img[@src$=png]").pngfix();

Code: Select all

function ie6PngFix(){
    $(".content img[@src$=png]").pngfix();
    $(".sidebar ul").css({
        background: "none",
        filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+urlRoot+"/images/BKGmodelsBox_grad.png', sizingMethod='scale')"
    });
and on the other page, this line is the problem

Code: Select all

if (navigator.userAgent.toLowerCase().indexOf('msie 6')!=-1){ ie6PngFix(); }
In both cases, JavaScript on the page doesn't work at all and IE reports:
ERROR: Object doesn't support this property or method

Everything works fine when I remove those lines... only the transparent PNG's in IE6 are broken... and I need them badly.
What troubles me that everything was working fine for a year and then a couple of days ago suddenly this hell broke loose...
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: GOING CRAZY... can't find the error in a few lines of co

Post by pickle »

Use. JQuery's. Built. In. Browser. Detection.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
maros174
Forum Newbie
Posts: 11
Joined: Tue Mar 02, 2010 7:23 am

Re: GOING CRAZY... can't find the error in a few lines of co

Post by maros174 »

pickle wrote:Use. JQuery's. Built. In. Browser. Detection.
Tried...it doesn't solve the problem.

Code: Select all

if ($.browser.msie && $.browser.version.substr(0,1)<7){
                $("#pdfPopup img[@src$=png]").pngfix();
                $("#pdfPopup .sidebar ul").css({
                    background: "none",
                    filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+urlRoot+"/images/BKGmodelsBox_grad.png', sizingMethod='scale')"
                });
            }
This works in IE7 and IE8 (problem line commented)... no error and JavaScript loads fine.
But I need transparent PNG's in IE6 badly... and this solution turns that functionality off (it worked for a year, until a couple of day ago...)

Code: Select all

if (navigator.userAgent.toLowerCase().indexOf('msie 6')!=-1){
                //$("#pdfPopup img[@src$=png]").pngfix();
                $("#pdfPopup .sidebar ul").css({
                    background: "none",
                    filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+urlRoot+"/images/BKGmodelsBox_grad.png', sizingMethod='scale')"
                });
            }
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: GOING CRAZY... can't find the error in a few lines of co

Post by Eran »

A couple of things:

1. check the values to see they return what you expect (debugging 101)

Code: Select all

alert($.browser.msie);
alert($.browser.version.substr(0,1)<7);
2. You can also use IE6 css rules to apply the transparency filter instead of using javascript. I'd consider this alternative as it's better all around (works without javascript, better performance, etc)
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: GOING CRAZY... can't find the error in a few lines of co

Post by Benjamin »

I would check the ID's for all the elements on the page. IE has issues with names that may be used elsewhere, such as id="form" etc. So that is where I would start.
Post Reply