Обсуждения » Разработка

Whats the problem about jQuery in GM?

§
Создано: 22.01.2016
Изменено: 22.01.2016

Whats the problem about jQuery in GM?

//index.html

<!DOCTYPE html>
<html>
<head>
<title>Test!</title>
<script src="http://code.jquery.com/jquery-2.2.0.js"></script>
</head>
<body>
<input type="button" id="btn" value="SAVE" />
</body>
</html>

//user script

// ==UserScript==
// @name        test
// @namespace   test
// @include     http://localhost:8055/
// @require     http://code.jquery.com/jquery-2.2.0.js
// @run-at      document-end
// @grant       unsafeWindow
// @version     1
// ==/UserScript==

$$ = unsafeWindow.jQuery; //NOT WORK
//$$ = jQuery; //WORK

var el = document.createElement('a');
el.innerHTML = 'click'
el.id = 'clk'
document.body.appendChild(el)

$$('#lll').click(function(){
  alert("clicked");
})

I dont know whats wrong with jQuery? The event will not be triggered when using unsafeWindow.jQuery, but it works when using jQuery loaded by GM. Anyone can tell me what happened?

Why are you trying to use the page's jQuery? There's no need to since you can just @require like you did in your example. Greasemonkey made some changes to the sandbox and it's now harder to do what you're trying to do: https://stackoverflow.com/questions/24719256/error-permission-denied-to-access-property-handler
You also have a bunch of missing semicolons and misspelled '#clk'

Ответить

Войдите, чтобы ответить.

长期地址
遇到问题?请前往 GitHub 提 Issues。