Difference between revisions of "Include"

From FirebugWiki
Jump to: navigation, search
(first draft)
 
(Mention that jquery is proposed by default in the aliases)
 
(4 intermediate revisions by 2 users not shown)
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)'''
  
== Example of use ==
+
=== alias ===
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).
+
Alias name for the included script. '''(optional for definition, required for usage)'''
 +
 
 +
'''New:''' Now by default, the "jquery" alias is proposed to get the ''jquery-latest.js'' script. So to include jquery, you can use the command below:
  
But the webpage that you debug does not use it. Fortunately, the ''include'' command allows you to import jQuery:
 
 
<source lang="javascript">
 
<source lang="javascript">
include("http://code.jquery.com/jquery-latest.js");
+
include("jquery")
 
</source>
 
</source>
  
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.
+
== Example of use ==
 +
The simplest usage is as follow:
 +
<source lang="javascript">
 +
include("http://code.jquery.com/jquery-latest.min.js")
 +
</source>
 +
 
 +
If you often include the same script (e.g. jqueryfying your page), you can create a handy alias:
  
Fortunately again(!), you can also create an alias for this URL:
 
 
<source lang="javascript">
 
<source lang="javascript">
include("http://code.jquery.com/jquery-latest.js", "jquery");
+
include("http://code.jquery.com/jquery-latest.min.js", "jquery")
 
</source>
 
</source>
  
and reuse it every time you want by passing the alias instead of the URL when you call ''include'':
+
and reuse it like below:
 +
 
 
<source lang="javascript">
 
<source lang="javascript">
include("jquery");
+
include("jquery")
 
</source>
 
</source>
  
Some time later, you do not remember the alias you have created. To list them, you type this command:  
+
Note that aliases are persistent across Firefox restarts.  
 +
 
 +
To list the aliases, you are offered this command:  
 
<source lang="javascript">
 
<source lang="javascript">
 
include();
 
include();
Line 51: Line 58:
 
[[File:IncludeTableExample.png]]
 
[[File:IncludeTableExample.png]]
  
You notice that you will not use vaporjs anymore. You type this command to delete it:
+
To remove an alias (for example, vaporjs), type this command:
 +
 
 
<source lang="javascript">
 
<source lang="javascript">
 
include(null, "vaporjs");
 
include(null, "vaporjs");
 
</source>
 
</source>
  
Enjoy !
+
[[Category:Firebug]]
 +
[[Category:UI]]
 +
[[Category:API]]

Latest revision as of 04:06, 28 December 2013

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

Syntax[edit]

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

Parameters[edit]

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

url[edit]

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

alias[edit]

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

New: Now by default, the "jquery" alias is proposed to get the jquery-latest.js script. So to include jquery, you can use the command below:

include("jquery")

Example of use[edit]

The simplest usage is as follow:

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

If you often include the same script (e.g. jqueryfying your page), you can create a handy alias:

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

and reuse it like below:

include("jquery")

Note that aliases are persistent across Firefox restarts.

To list the aliases, you are offered this command:

include();

And you are returned this table:

IncludeTableExample.png

To remove an alias (for example, vaporjs), type this command:

include(null, "vaporjs");