Favicon
WET v4.0 or later
This feature is exclusive to WET v4.0 or later.
Purpose
This plugin provides the ability to add and update a web page's favicon.
Use when
- Adding a mobile favicon to a web page.
- Dynamically updating the favicon of a web page.
Working example
How to implement
Add a mobile favicon:
- Add a favicon to the web page using a link element:
<link href="favion.ico" rel="icon" type="image/x-icon">
- Optionally specify the mobile favion's filename, path, rel attribute and sizes attribute:
<link href="favion.ico" rel="icon" type="image/x-icon" data-filename="my-mobile-favicon.ico" data-path="/path/to/favicon/" data-rel="apple-touch-icon-precomposed" data-sizes="57x57">
Update an existing favicon's href attribute:
- Using JavaScript, get a reference to the favicon's link element:
var $favicon = $( "link[rel='icon']" );
- Trigger the
icon.wb-favicon
event on the favicon element:
Note: the update of the favicon's href attribute will be based on its data-path and data-filename attributes.$favicon.trigger( "icon.wb-favicon" );
Configuration options
All configuration options of the plugin are controlled with data attributes:
Option | Description | How to configure | Values |
---|---|---|---|
data-filename | Filename of the mobile favicon. It is appended to the favicon's path (specified by data-path). | Set to the filename of the mobile favicon. |
|
data-path | Full path to the mobile favicon. | Set to the full path of the mobile favicon. |
|
data-rel | Favicon rel attribute. | Set to the desired rel attribute value of the favicon. |
|
data-sizes | Favicon sizes attribute. | Set to the desired sizes attribute value of the favicon. |
|
Events
Document the public events that can be used by implementers or developers.
Event | Trigger | What it does |
---|---|---|
wb-init.wb-favicon | Triggered manually. | Initializes the plugin and creates a mobile favicon if it doesn't already exist. Note: the favicon plugin will be initialized automatically unless the link element is added after the page has already loaded. |
mobile.wb-favicon | Triggered manually and during plugin initialization. | Adds or updates the mobile favicon on the web page. This will only update a mobile favicon that was added by the plugin. |
icon.wb-favicon | Triggered manually. | Updates the favicon's href attribute based on its data-filename and data-path attributes. |
Source code
- Date modified: