1. Code for adding IE browser to favorites
Window. external. addFavorite (sURL, sTitle );
Parameters:
SURL: the address of the complete website page added to favorites
STitle: name of the page title added to the favorites folder.
Example:
<A href = '# 'onclick = "javascript: window. external. AddFavorite ('HTTP: // www.domain.com', 'name');"> Add to favorites </a>
2. Code for adding Firefox to favorites
In Firefox, it is called adding bookmarks (favorites). There are two methods for code. One method is similar to that in IE browser, but it is window. external. addFavorite is replaced by sidebar. addPanel, the other one is very simple. You only need to add a parameter.
Method 1:
Window. sidebar. addPanel (sTitle, sURL ,"");
Parameters
SURL: complete link to the favorite website page
STitle: name of the favorite website page
Example:
<A href = '# 'onclick = "javascript: window. sidebar. addPanel ('name', 'HTTP: // www.domain.com ', '');"> Add to favorites </a>
Note that the parameter sequence of the addPanel function is the opposite of that of addFavorite.
Method 2:
Add the rel = "sidebar" attribute to the link
Example:
<A href = http://www.domain.com title = "name" rel = "sidebar"> favorite site </a>
Note: The title attribute here is the name of the favorite website page.
3. methods compatible with Firefox and IE browsers
Since Firefox provides two methods, we can use either Firefox or IE.
Method 1:
Here we use a flexible method to solve this problem, and the code is clearer. This is the best way!
Add to favorites
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
It should be noted that ie is the domain name in front, firefox is the domain name in the backdoor, and a blank character is left at the end.
Method 2:
This is the simplest method, with only one sentence.
<A href = 'HTTP: // www.domain.com 'onClick = "javascript: window. external. addFavorite ('HTTP: // www.domain.com ', 'name'); "title =" name "rel =" sidebar "> Add to favorites </a>
But this method has some problems, that is, the link address is opened at the same time in IE. So let's optimize it!
<A href = "www.domain.com/" onclick = "window. external. addFavorite (this. href, this. title); return false; "title = 'name' rel =" sidebar "> Add to favorites </a>
That's okay, haha! It is also compatible with IE 6, IE7, Firefox, Opera, and other browsers.
For more codes with better compatibility, you can search for articles from the beginning.
Add the Home Page function to favorites at the bottom.
Set as homepage-add to favorites
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]