简体   繁体   中英

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!

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");

This cannot be done, due to the browser's security policy against XSS (cross-site scripting).

Even with an iframe, the browser will prevent the external window from scripting the inner window.

The best you can do is load the page, then click the bookmarklet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM