SoFunction
Updated on 2025-02-28

js Firefox Add to favorites function code Compatible with Firefox and IE

The complete code is as follows: There are also prompts under Chrome. To be honest, this type of code is generally used under IE, and other browsers only give a prompt.

<script type="text/javascript">
//Set as homepagefunction SetHome(obj,url){
  try{
    ='url(#default#homepage)';
    (url);
  }catch(e){
    if(){
     try{
       ("UniversalXPConnect");
     }catch(e){
       alert("Sorry, this operation was rejected by the browser!\n\nPlease enter "about:config" in the browser address bar and press Enter and set [.codebase_principal_support] to 'true'");
     }
    }else{
    alert("Sorry, the browser you are using cannot do this.\n\nYou need to manually transfer ["+url+"] Set as home page.");
    }
 }
}
 
//Save this sitefunction AddFavorite(title, url) {
 try {
   (url, title);
 }
catch (e) {
   try {
    (title, url, "");
  }
   catch (e) {
     alert("Sorry, the browser you are using cannot complete this operation.\n\nAdd to favorites failed. Please use Ctrl+D to add it after entering the new website");
   }
 }
}
</script>
&lt;a href="javascript:void(0);" onclick="SetHome(this,'https://');">Set as home page</a>&lt;div class="text text2"&gt;&lt;a href="javascript:void(0);" onclick="AddFavorite('I','https://')"&gt;receive * Book stand&lt;/a&gt;

Here are some specific explanations:

1. Code to add favorites to IE browser
(sURL, sTitle);
parameter:
sURL: full website page address added to favorites
sTitle: The title name of the website page added to your favorites.
Example:
<a href='#' onClick="javascript:('', 'name');">Add to favorites</a>

2. Code to add the Firefox browser to favorites
In Firefox, it is called adding bookmarks (favorites). There are two ways of code. One is similar to the IE browser method, but it is replaced by it. The other is very simple. You only need to add one parameter.
The first method:
(sTitle, sURL, "");
parameter
sURL: Collection of full links to the website page
sTitle: The name of the page of the collection site
Example:
<a href='#' onClick="javascript:('name','','');">Save this site</a>
Note here that the parameter order of the addPanel function is exactly the opposite of addFavorite.
The second method:
Add rel="sidebar" attribute on the link
Example:
<a href= title="name" rel="sidebar">Save this site</a>
Note: The title attribute here is the name of the collection website page.
3. How to be compatible with Firefox and IE browsers
Since Firefox provides two methods, we can use two methods to be compatible with Firefox and IE browsers.
The first method:
Here is a workaround to solve this problem, and the code is relatively clear. This is the best way!


[Ctrl+A Select all Note:Introducing external Js requires refreshing the page before execution]

It should be noted that ie is the domain name in front, firefox is the domain name in backdoor, and a empty character is left at the end.
The second method:
This is the easiest method, only one sentence.
<a href='' onClick="javascript:('',' Name');" title="Name" rel="sidebar">Save this site</a>
However, there are some problems with this method, which is to open the address in the link next time in IE. Then let’s optimize it!
<a href="/" onclick="(,);return false;" title='name' rel="sidebar">Add to favorites</a>
That's fine, haha! It is also compatible with IE6, IE7, Firefox, Opera and other browsers.
More compatibility with better code, you can search for my previous posts.

My bottom Add to Favorites Set as homepage function

[Ctrl+A Select all Note:Introducing external Js requires refreshing the page before execution]