简体   繁体   English

如何在jQuery noConflict模式下加载远程脚本?

[英]How do I load remote script in jQuery noConflict mode?

I want to load a remote script which is not utilizing jQuery noConflict mode from a WordPress website, which is. 我想从WordPress网站加载未使用jQuery noConflict模式的远程脚本。 Effectively I need to wrap the remote script in noConflict mode. 实际上,我需要将远程脚本包装为noConflict模式。 I thought something like this would do the trick, but apparently not. 我以为这样的事情可以解决,但显然不行。

<script>
  jQuery.noConflict();
  jQuery(document).ready(function($) {
    $.getScript('http://remote-domain.com/load/remote/script');
  });
</script>

I thought this would be straightforward, but couldn't see anything for remote scripts on Googling and checking other Stack Overflow questions. 我以为这很简单,但是在Googling上查看远程脚本并检查其他Stack Overflow问题时什么也看不到。 Is it possible? 可能吗? Am I missing something? 我想念什么吗? Am I just being dim? 我只是昏昏欲睡吗?

See this CodePen featuring the actual script I am having issues with 请参阅此CodePen,其中包含我遇到的实际脚本

No conflict should be done one once before all scripts. 在所有脚本之前都不应发生一次冲突。 I see no other problems in your code. 我看不到您的代码中的其他问题。

But keep in mind, that jQuery will do an AJAX request for this file and you use a remote URL. 但是请记住,jQuery将对此文件执行AJAX请求,并且您使用远程URL。 There might be problems when your browser and/or server dosesn't allow this. 当您的浏览器和/或服务器不允许这样做时,可能会出现问题。

jQuery.noConflict();

jQuery(function() {
    jQuery.getScript('http://remote-domain.com/load/remote/script');
});

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

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