0

Please forgive me if this has been answered before but I've searched and searched and haven't been able to find a solution to my problem.

I'm using Greasemonkey in Firefox and Tampermonkey in Chrome to automatically open a link on a webpage I visit frequently. Below is the javascript code:

// ==/UserScript==
var link = document.querySelector('[href*="/cgi/admin/user/ssh_login/"]');
var url = link.getAttribute('href');
var sshlink = "https://"+document.domain+url;
//alert(sshlink);
var openWindow = window.open(sshlink,"ssh","location=1,status=1,scrollbars=1,width=100,height=100");
window.blur();
setTimeout(function(){openWindow.close();},2000);

This opens the link in a new popup and closes it after 2000ms. What I'd actually prefer is to have the openWindow.close(); happen after the popup's window.open is done loading. I've tried both of these solutions and neither have worked.

What am I doing wrong? Does anyone know what I can do differently to accomplish what I want?

Community
  • 1
  • 1

1 Answers1

0

There is no need to use a pop up window to make a GET request to the same server. Just make an Ajax call.

var oReq = new XMLHttpRequest();
oReq.open("GET", sshlink);
oReq.send();

No need to worry about pop up blockers and if the window loaded. The code above will make a GET request to the url and it does nothing with the response that comes back. Basic tutorial on Ajax

epascarello
  • 204,599
  • 20
  • 195
  • 236
  • So I just used that code that you gave me above and now it's not loading the link at all. Not sure what I did wrong. `// ==/UserScript== var link = document.querySelector('[href*="/cgi/admin/user/ssh_login/"]'); var url = link.getAttribute('href'); var sshlink = "https://"+document.domain+url; var oReq = new XMLHttpRequest(); oReq.open("GET", sshlink); oReq.send();` – Mister Pyrrhuloxia Oct 07 '15 at 16:34
  • You are not going to see it load anything unless you look at the developer console and watch the request. – epascarello Oct 07 '15 at 16:44
  • I'm not even seeing the request loading in the console though. – Mister Pyrrhuloxia Oct 07 '15 at 16:51