javascript - Can a function defined in a bookmarklet be called from a page-level script? -


I have a bookletlet that needs to open new window / tab to avoid popup blocker, bookmarklet i.e. call window.open () method.

However, I want to keep updating the bookmarks by loading external javascript files. To do this, the bookmarklet must add a script node to the DOM. If I was putting window.open () code in one of these externally loaded scripts, then the popup blocker would block it from its page-level.

What should I know is whether I can make an envelope around my code in the book window.open () , then it is loaded externally Tell the script? What is the scope and what is allowed on a rap such as this?

I have a solution which is not correct but meets the requirements:

Here is the bookmarklet code:

  javascript: window.open (window.location); Window.location = "http://www.google.com/"§var%20s=document.createElement('script');s.setAttribute ('src','http://my-script.js') ; Document.body AppendChild (s); Zero (0);  

Readable step-by-step equivalents:

  window.open (window.location); // Clone the current tab window. Location = "http://www.google.com/"; // Go to the desired page url var s = document.createElement ('script'); // Create script s.setAttribute ('src', 'http: //my-script.js'); // document.body.appendChild (s); // Embed this in the current document  

Only one problem persists: The page you want to show is not active by default. Cloned.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -