I am trying to create some sort of workflow in GreaseMonkey.
I start with GreaseMonkey defining jQuery if it isn’t already defined:
/*! jQuery v1.7.1 jquery.com | jquery.org/license */
if (typeof jQuery == 'undefined')
(function(a,b).......function(){return f})})(window); // packed version
jQuery.noConflict();
/*! end of jQuery */
Then, it periodically checks a web page (jQuery.ajax/type=get/url:window.location.href).
When some condition is met, a window is created using
var url = <some page on the same domain>
var opened = window.open(url, "XYZ");
The question is how to get a button on the opened window to click. Let’s say on the page there is a button
<input type="button" id="clickme"
I’ve tried the obvious such as
opened.document.getElementById('clickme').click()
jQuery(opened.document).find('#clickme').click()
But neither work. This is probably a GreaseMonkey issue so would like to see if anyone has something similar working. My current workaround is to set up another GreaseMonkey script against the opened url which clicks the button if window.name = ‘XYZ’.
The question is pretty vague; I’m assuming you’re creating a window using
window.openor something to that effect, and want to interact with the DOM inside.You should be able to use the reference to the newly-opened window as you would use the
windowvariable in regular JavaScript:becomes
If you’ve got jQuery loaded inside the window, then you can do
As for how to simulate a click on a button inside that window:
or using jQuery:
Edit: Without using jQuery from inside the new window (test it out on jsFiddle):