The code for adding js Firefox to favorites is compatible with Firefox and IE

Source: Internet
Author: User

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]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.