Discussions » Development

Whats the problem about jQuery in GM?

Posted: 2016-01-22
Edited: 2016-01-22

Whats the problem about jQuery in GM?


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

//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'


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?

Posted: 2016-02-01

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'

Post reply

Sign in to post a reply.