开发者

Web custom control and checking for existing javascript references?

I am creating a custom control and had a thought before I began. My control relies on the jQuer开发者_如何学运维y library to work. What if the user already has a version of the library already on their page. Will this effect anything? If my version is newer / older and my control will only work with that version of the libaray, what should I do? Thanks


Well, you could check in your scripts your control is rendering if the jQuery function is defined.

if (typeof jQuery == 'undefined') {  
  someLoadMethodJustForExample("jquery");
}

If not, it isn't loaded. And you should load it.

If there's already another version loaded jQuery.fn.jquery; will return you a version string like "1.4.4". So you could display an error message and tell the person to reference another jQuery version which is compatible with your control or just let your control do the work.

Google does have a dynamic loading function for jQuery (and a lot of other frameworks) you could use.

google.load("jquery", "1.4.4");

Hope that helps.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜