Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在Bookmarklet中加载jQuery和jQuery UI,如果它们是';您还没有加载_Javascript_Jquery_Jquery Ui - Fatal编程技术网

Javascript 在Bookmarklet中加载jQuery和jQuery UI,如果它们是';您还没有加载

Javascript 在Bookmarklet中加载jQuery和jQuery UI,如果它们是';您还没有加载,javascript,jquery,jquery-ui,Javascript,Jquery,Jquery Ui,我正在开发一个bookmarklet,它需要访问jqueryui和jquerymin。当然,需要考虑的是页面可能已经加载了jquery,应该避免冲突 使用Ben Alman在Find at的代码,我已经能够优雅地引入jQuery并在UI中进行黑客攻击以加载,但似乎存在延迟问题,而jQuery UI还并没有准备好立即加载 在执行实际代码之前,是否有更好的方法处理按顺序加载两个脚本 (function( window, document, jQuery, req_version, callback,

我正在开发一个bookmarklet,它需要访问jqueryui和jquerymin。当然,需要考虑的是页面可能已经加载了jquery,应该避免冲突

使用Ben Alman在Find at的代码,我已经能够优雅地引入jQuery并在UI中进行黑客攻击以加载,但似乎存在延迟问题,而jQuery UI还并没有准备好立即加载

在执行实际代码之前,是否有更好的方法处理按顺序加载两个脚本

(function( window, document, jQuery, req_version, callback, callback_orig, parent, script ){

  if ( !window[jQuery] || req_version > window[jQuery].fn.jquery ) {
    parent = document.documentElement.childNodes[0];
    script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js';
    parent.appendChild(script);

    callback_orig = callback;
    callback = function($, L) {
      '$:nomunge, L:nomunge';
      $(script).remove();
      callback_orig( $, L );
    };
  }

  if (typeof jQuery.ui == 'undefined'){
   parent = document.documentElement.childNodes[0];
   scriptui = document.createElement('script');
   scriptui.type = 'text/javascript';
   scriptui.src = 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.js';
   parent.appendChild(scriptui);
   alert('Loading your matches...');
  } 

  (function loopy($){
    '$:nomunge'; // Used by YUI compressor.

    ( $ = window[jQuery] ) && req_version <= $.fn.jquery
      ? callback( parent ? $.noConflict(1) : $, !!parent ) : setTimeout( loopy, 50 );
  })();

})( window, document, 'jQuery', '1.3.2',

 function($,L) {
    '$:nomunge, L:nomunge';   

<all the jquery stuff goes here>
(函数(窗口、文档、jQuery、请求版本、回调、回调源、父级、脚本){
如果(!window[jQuery]| | req_version>window[jQuery].fn.jQuery){
父节点=document.documentElement.childNodes[0];
script=document.createElement('script');
script.type='text/javascript';
script.src=http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js';
parent.appendChild(脚本);
callback_orig=回调;
回调=函数($,L){
“$:nomunge,L:nomunge”;
$(脚本).remove();
原币($,L);
};
}
if(typeof jQuery.ui==“未定义”){
父节点=document.documentElement.childNodes[0];
scriptui=document.createElement('script');
scriptui.type='text/javascript';
scriptui.src=https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.js';
parent.appendChild(scriptui);
警报('正在加载您的匹配项…');
} 
(函数循环($){
“$:nomunge”;//由YUI压缩机使用。

($=window[jQuery])&&req_version请参见此处的要点-这是一个用于加载jQuery的bookmarklet模板,但您可以在执行之前指定要加载的其他脚本和css

你可以这样初始化它

编辑:如果需要加载依赖项,可以创建一个数组,并根据不同的条件将内容推入其中

var jsDependencies = [];

// This will only load jQuery UI if it does not exist already.
// Of course if you rely on the page's copy, you have to do some 
// more advanced things to check for versions and whatnot.
if(!window.jQuery || !window.jQuery.ui){
  jsDependencies.push('http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js');
}

var MyBookmarklet = MyBookmarklet || new Bookmarklet({
  // debug: true, // use debug to bust the cache on your resources
  css: ['/my/style.css'],
  js: jsDependencies,
  // jqpath: '/my/jquery.js', // defaults to google cdn-hosted jquery
  ready: function(base) { // use base to expose a public method
    base.init = function(){
      // doStuff();
    }    
    base.init();
  }
});

啊,说得太快了。我正在查看的页面已经加载了UI,并添加了js:[',正在生成错误:arr未定义,第74行(git pub的63)抱歉。
arr
应该改为
scripts
。我已经更新了要点。另外,请确保您使用“https://”、“http://”或“//”。最后一个是协议相关url。脚本需要完全限定的URI来加载内容。嗯,您可以尝试用jQuery替换$。它们可能有jQuery在noConflict模式下使用。我将尝试一个基于此的我自己的bookmarklet,并让您知道我发现了什么。接下来…用jQuery()替换$()我们能够将jQuery的基础加载到Amazon和其他各种有问题的网站上。但是在加载某种类型的UI时仍然存在冲突,所有UI功能都失败了。你不知道如何解决这个问题吗?