I'm trying to figure out how I can get my bookmarklet to work the way I want it to. Here's my issue. I have a JS bookmarklet that scrapes a secure web page and uses those DOM elements to run my code.
My issue is, when I click on my bookmarklet, it opens the new page in a new tab and immediately starts running the code I intend to run for the newly opened page. For example, a prompt window that I'm using to store user input runs immediately on the current page I'm on when I click the bookmarklet. My intended behavior is to first open the new page in a new tab, load the page, then run the prompt and the rest of the code using the DOM elements of that new page. I'm using a secure webpage so I'll use google homepage for an example.
Here's an example:
javascript: (function() {
function OpenInNewTab(url){
var win = window.open(url);
win.focus();
}
OpenInNewTab("https://www.google.com/?gws_rd=ssl");
var prmt = prompt("Enter a date:");
window.onload = prmt;
})();
Ultimately, I'd like the code to do 3 things.
- Open the new window in a new tab when clicking on it from any page
- Be in that new tab and load the page
- Then run my code on that newly opened page
I hope I have explained myself well! As always, any information is greatly appreciated.