开发者

How to make javascript working in Firefox also work in IE

Hi I have this JavaScript code, which is working perfect in All browsers except IE. How can I make it work in IE versions too. This code creates an automatic thumbnail and summary of any post

function removeHtmlTag(strx,chop){ 
    if(strx.indexOf("<")!=-1)
    {
        var s =开发者_如何学JAVA strx.split("<"); 
        for(var i=0;i<s.length;i++){ 
            if(s[i].indexOf(">")!=-1){ 
                s[i] = s[i].substring(s[i].indexOf(">")+1,s[i].length); 
            } 
        } 
        strx =  s.join(""); 
    }
    chop = (chop < strx.length-1) ? chop : strx.length-2; 
    while(strx.charAt(chop-1)!=' ' && strx.indexOf(' ',chop)!=-1) chop++; 
    strx = strx.substring(0,chop-1); 
    return strx+'...'; 
}

function createSummaryAndThumb(pID, pURL, pTITLE){
    var div = document.getElementById(pID);
    var imgtag = "";
    var img = div.getElementsByTagName("img");
    var summ = summary_noimg;
    if(img.length>=1) { 
        imgtag = '<span><a href="'+ pURL +'" title="'+ pTITLE+'"><img src="'+img[0].src+'" width="'+img_thumb_width+'px" height="'+img_thumb_height+'px"/></a></span>';
        summ = summary_img;
    }

    var summary = imgtag + '<div style="display:none;">' + removeHtmlTag(div.innerHTML,summ) + '</div>';
    div.innerHTML = summary;
}


One possible culprit is the use of indexOf. It's not supported in IE (at least 7/8, am not sure about 9/10).

Related to "how to fix array indexof in javascript for ie browsers"


try with IE 7/8

or

if ($.browser.msie && $.browser.version.substr(0,1)<7)
//your code goes here

this code is only work for IE 5/6. For firefox or other browser write your code at else statement.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜