Greasemonkey access violation: unsafeWindow cannot call GM_xmlhttpRequest.
解決方法如下:
unsafeWindow.someObject.registerCallback(function(asin) { window.setTimeout(function() { // 重點是利用 window.setTimeout GM_xmlhttpRequest({ method: "GET", url: "http://www.amazon.com/asin/" + asin; }); }, 0); // <<< });
實際例子
$("span[name!=NOT_AVAILABLE]").click(function(){ GM_openInTab(entrezGene+$(this).attr("name"),1); }).mouseover(function(){ var url=url+$(this).attr("name")+".htm"; window.setTimeout(function(ref){ GM_xmlhttpRequest({ method: "GET", url: url+"", onload: function(xhr) { ref.attr("title","Information from Entrez Gene|"+xhr.responseText).cluetip( {width:400,splitTitle: '|',arrows: true,dropShadow: false, cluetipClass: 'gene', waitImage: true} ); } }); },0,$(this)); // 用這種方法可以將 $(this) 傳進去 });
沒有留言:
張貼留言