JavaScript in bookmarklet to open webpage and then select option from dropdown list on that webpage?

58 Views Asked by At

I have written a JavaScript snippet for use as a bookmarklet in Firefox. It will open a webpage and then select an option from a dropdown menu and submit. It works as intended, except I have to click the bookmark twice, first opening the page, and then to select the option in the dropdown list. Is there a solution to do everything with just one click on the bookmark (perhaps by delaying execution)?

window.open("https://www.foreca.se/Sverige/Stockholm/Stockholm", '_self');

document.querySelector("#stationForm > select.stationSelect > option[value='1020002460']").selected = 'selected';
document.getElementById("stationForm").submit();
1

There are 1 best solutions below

0
loxia_01 On

It seems it is not possible. The bookmarklet can only act on an already open web page according to this post.

However you can instead achieve the same with a userscript in for example Tampermonkey userscript manager.