简体   繁体   English

包括在网站中使用jquery的外部JavaScript?

[英]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. 我想编写简单的javascript,用于收集访问者信息,脚本需要运行JQuery。

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"... 然后我想提供该脚本,所以其他网站可以使用脚本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部分,如何包含JQuery,我不知道将包含它的网站是否加载了JQuery,如果我强制加载JQuery我不想引起冲突或任何问题使用我的脚本的网站。

只需在脚本中加入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. 您可以检测脚本开头是否加载了jQuery,以警告用户不包含jQuery。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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