Include

From FirebugWiki

(Difference between revisions)
Jump to: navigation, search
(first draft)
(Changed parts of the formatting to be conform with other Command Line APIs)
Line 1: Line 1:
-
Downloads and executes a remote script in a web page. Specially useful to import libraries for the Command Line.
+
Downloads and executes a remote script in a web page. Especially useful to import libraries for using them inside the [[Command Line]].
== Syntax ==
== Syntax ==
 +
<source lang="javascript">
 +
include()
 +
</source>
-
=== include(url) ===
+
<source lang="javascript">
-
Includes a remote script.
+
include(url[, alias])
-
==== Parameters ====
+
</source>
-
* '''url''': the url of the script to include
+
-
=== include(url, alias) ===
+
<source lang="javascript">
-
Includes a remote script and links it to an alias.
+
include(alias)
-
==== Parameters ====
+
</source>
-
* '''url''': the url of the script to include; if set to ''null'', the alias is deleted
+
-
* '''alias''': the alias to link to the url
+
-
=== include(alias) ===
+
== Parameters ==
-
Includes a remote script described by its alias.
+
If <code>include()</code> is written without parameters, it prints a table with all previously specified aliases.
-
==== Parameters ====
+
-
* '''alias''': the alias for the script to include
+
-
=== include() ===
+
=== url ===
-
Prints the table with the aliases and the URL they refers to.
+
URL of the script to include. If set to <code>null</code>, alias is removed. '''(optional)'''
 +
 
 +
=== alias ===
 +
Alias name for the included script. '''(optional for definition, required for usage)'''
== Example of use ==
== Example of use ==

Revision as of 20:34, 3 November 2012

Downloads and executes a remote script in a web page. Especially useful to import libraries for using them inside the Command Line.

Contents

Syntax

include()
include(url[, alias])
include(alias)

Parameters

If include() is written without parameters, it prints a table with all previously specified aliases.

url

URL of the script to include. If set to null, alias is removed. (optional)

alias

Alias name for the included script. (optional for definition, required for usage)

Example of use

Let's assume you want to type a series of commands in the javascript console. And for convenience, you would like to use a Framework (let's say jQuery).

But the webpage that you debug does not use it. Fortunately, the include command allows you to import jQuery:

include("http://code.jquery.com/jquery-latest.js");

Now you are happy with this ability to use your favorite library on any page. But typing every time the url minds you a lot.

Fortunately again(!), you can also create an alias for this URL:

include("http://code.jquery.com/jquery-latest.js", "jquery");

and reuse it every time you want by passing the alias instead of the URL when you call include:

include("jquery");

Some time later, you do not remember the alias you have created. To list them, you type this command:

include();

And you are returned this table:

IncludeTableExample.png

You notice that you will not use vaporjs anymore. You type this command to delete it:

include(null, "vaporjs");

Enjoy !

Personal tools