Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I build quite a lot of bookmarklets to automate my every day's work. Now I faced a problem: I would like (by clicking on a bookmarklet) to open a page in web browser (I use Internet Explorer 8) and apply some specific operation on its interface.

The web application is old and does not provide some advanced option like table filtering. I have this functionality already written, now I would like to open a web app and apply my JS code by one click on bookmarklet.

So I would like 3 steps to by done by one click:

  1. Open some webpage.
  2. Wait for webpage to be fully loaded.
  3. Run some JS command, let say alert('test');

I tried few times, but it seems impossible to me. So I would like to be sure: is it do-able?

share|improve this question

migrated from webapps.stackexchange.com Jan 10 '14 at 16:20

This question came from our site for power users of web applications.

    
Which browser are you using? – Sathya Jan 10 '14 at 14:37
    
@Sathya - Internet Explorer 8, unfortunately :) – boleslaw.smialy Jan 10 '14 at 15:47
    
Might be possible if you load the page in a frame. – Daniel Beck Jan 11 '14 at 9:38
    
@DanielBeck - interesting idea, I've never thought about it. I will check and let you know! Cheers! – boleslaw.smialy Jan 13 '14 at 7:51
    
@DanielBeck - totally forgot about SOP policy. I am not allowed to run JS action in iframe because of different origin of "bookmarklet scope" and the iframe I've created. – boleslaw.smialy Jan 14 '14 at 9:44

I have this functionality already written, now I would like to open a web app and apply my JS code by one click on bookmarklet.

Use a remote script via window.open and window.opener:

  /* Web App */
  <script>
  window.open('remote.html')
  </script>

  /* remote.html */
  <script>
  window.opener.onload = function(){}
  </script>

Add the script tag to the Web App via the bookmarklet, then it will do the rest.

References

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.