开发者

My custom javascript is conflict with sharepoint javascript (sharepoint 2010)

I am using custom javascript file([mootools-1.2-cor开发者_如何学编程e.js][1]) in custom application page in sharepoint(2010).I get type mismatch error in wpadder.js(Sharepoint Javascript file which resides in 14/layouts).Could anyone provide a solution for this issue ?


I would recommend a google search for type mismatch error wpadder.js - first link = http://labs.steveottenad.com/type-mismatch-on-wpadder-js/


I stumbled upon this question today because I had the same error. The link pointed by Brian Brinley (http://labs.steveottenad.com/type-mismatch-on-wpadder-js/) actually helped, because it mentions that:

Sharepoint (and possibly IE in general) has issues with any plugins/scripts that try to extend the Array Prototype.

The code I was working on had extended Array.prototype to include an indexOf method.

if (!Array.prototype.indexOf) {
    Array.prototype.indexOf = function (obj, start) {
        for (var i = (start || 0); i < this.length; i++) {
            if (this[i] === obj) { return i; }
        }
        return -1;
    }
}

The error in wpadder.js disappeared as soon as I removed the above bit from the code.

As a substitute for the indexOf method, I wrote this:

// this function returns the index of the first occurrence 
// of the given item in a simple array
function indexOf(array, item, start) {
    for (var i = (start || 0); i < array.length; i++) {
        if (array[i] === item) {
            return i;
        }
    }
    return -1;
}

and replaced all array.indexOf(item) in the code with indexOf(array, item).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜