简体   繁体   中英

Including external javascript that uses jquery in the website?

I want to write simple javascript, something for collecting visitor info and the script needs JQuery to run.

Then I want to provide that script, so other websites can include/load it from me externaly, using script src="my_web/my_javascript.js"...

My dilemma is how to handle JQuery part, how to include JQuery, I don't know wheather the site that will include it has JQuery loaded or not, and if I force loading JQuery I don't want to cause conflicts or any problems on the site that uses my script.

只需在脚本中加入jquery - 将2连接在一起并缩小。

You can detect if jQuery is loaded at the beginning of your script, to warn the user to include it if it isn't.

if (typeof jQuery == 'undefined') {  
    alert("jQuery is required!");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM