Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load external JS from bookmarklet?

How can I load an external JavaScript file using a bookmarklet? This would overcome the URL length limitations of IE and generally keep things cleaner.

like image 721
Justin Avatar asked Sep 19 '08 23:09

Justin


People also ask

How do I import an external file into JavaScript?

To include an external JavaScript file, we can use the script tag with the attribute src . You've already used the src attribute when using images. The value for the src attribute should be the path to your JavaScript file. This script tag should be included between the <head> tags in your HTML document.

How do I save an external JavaScript file?

We can create external JavaScript file and embed it in many html page. It provides code re usability because single JavaScript file can be used in several html pages. An external JavaScript file must be saved by . js extension.

Where is the external JavaScript file stored?

The JavaScript file will be saved with a . The file can be saved anywhere in the Web Project directory. It is common practice to put JavaScript files in a folder named "javascript" or "src" when building web and mobile applications.

Can JavaScript be external?

The use of external JavaScript is more practical when the same code is to be used in many different web pages. Using an external script is easy , just put the name of the script file(our . js file) in the src (source) attribute of <script> tag.


1 Answers

2015 Update

Content security policy will prevent this from working in many sites now. For example, the code below won't work on Facebook.

2008 answer

Use a bookmarklet that creates a script tag which includes your external JS.

As a sample:

javascript:(function(){document.body.appendChild(document.createElement('script')).src='** your external file URL here **';})(); 
like image 74
Miguel Ventura Avatar answered Sep 21 '22 13:09

Miguel Ventura