简体   繁体   中英

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. Effectively I need to wrap the remote script in noConflict mode. 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. Is it possible? Am I missing something? Am I just being dim?

See this CodePen featuring the actual script I am having issues with

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. 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');
});

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