Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Run JavaScript after a Redirect with a Bookmarklet

I'm trying to write a bookmarklet where it will redirect a user to a page, and after their page is loaded, it'll position the web page at a specific y-coordinate via JavaScript.

I know this is possible to do before you redirect, but is there a way to do it when after you have redirected, the page will then re-position itself at that location?

I can think of using an iFrame as a potential solution, but that's not exactly what I want.

Thanks!

like image 680
J Kao Avatar asked Dec 05 '25 01:12

J Kao


1 Answers

This method does not do exactly what you want, but it merge two(or more) function into one bookmarklet. To do this try separate another command using "javascript:" protocol. When you click the bookmarklet, it will redirect you to the URL specified. However, you must click bookmark again to run the second part.

Example of URL:

javascript:if(window.location!="http://www.example.com/"){window.location="http://www.example.com/"}; javascript:alert("Click bookmarklet again");
like image 179
Kevin Law Avatar answered Dec 07 '25 16:12

Kevin Law



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!