Skip to content

Instantly share code, notes, and snippets.

@yuka2py
Forked from miya0001/gist:6145701
Last active December 20, 2015 14:39
Show Gist options
  • Save yuka2py/6148288 to your computer and use it in GitHub Desktop.
Save yuka2py/6148288 to your computer and use it in GitHub Desktop.
ページ内のjQueryの有無に関わらず、別のjQueryをロードしてスクリプトで利用する。既存のjQueryがあれば、それを変更しない。 ブックマークレットなどでの利用を想定。
(function(func){
var jq = document.createElement('script');
jq.src = '//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js';
jq.async = 1;
jq.onload = function() {
document.body.removeChild(jq);
func(jQuery.noConflict(true));
};
document.body.appendChild(jq);
})(function($){
alert($().jquery); //2.0.3
});
@yuka2py
Copy link
Author

yuka2py commented Aug 3, 2013

jsdo.it での確認コード:http://jsdo.it/yuka2py/load-another-jquery

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment