Add the code compatible with mainstream browsers such as 360/Firefox/Google/IE to the favorites page

Source: Internet
Author: User

No need to look for it. I have tried it many times. ie, Firefox, and Google browsers are irreversible compatibility.
The following is my simple solution. To completely solve this problem, you can create a Help page for adding a home page just like other mainstream websites.

Js Code:Copy codeThe Code is as follows: <script type = "text/javascript">
// Set it to the Home Page
Function SetHome (obj, vrl ){
Try {
Obj. style. behavior = 'url (# default # homepage) '; obj. setHomePage (vrl );
}
Catch (e ){
If (window. netscape ){
Try {
Netscape. security. PrivilegeManager. enablePrivilege ("UniversalXPConnect ");
}
Catch (e ){
Alert ("this operation is rejected by the browser! \ N enter "about: config" in the address bar of the browser, press enter \ n, set the value of [signed. applets. codebase_principal_support] To 'true', and double-click it. ");
}
Var prefs = Components. classes ['@ mozilla.org/preferences-service%1'}.getservice (Components. interfaces. nsIPrefBranch );
Prefs. setCharPref ('browser. startup. homepage', vrl );
} Else {
Alert ("your browser does not support this function. Follow these steps: 1. Open your browser settings. 2. Click set webpage. 3. Enter "+ vrl +" and click "OK. ");
}
}
}
// Add to favorites compatible with 360 and IE6
Function shoucang (sTitle, sURL)
{
Try
{
Window. external. addFavorite (sURL, sTitle );
}
Catch (e)
{
Try
{
Window. sidebar. addPanel (sTitle, sURL ,"");
}
Catch (e)
{
Alert ("failed to add to favorites, please add with Ctrl + D ");
}
}
}
</Script>

Call code:Copy codeThe Code is as follows: <li class = "fore1"> <a href = "javascript: void (0)" onclick = "SetHome (this, window. location) "> set to homepage </a> </li>
<Li class = "ge" >|</li>
<Li class = "fore2"> <a href = "javascript: void (0)" onclick = "shoucang (document. title, window. location) "> Add to favorites </a> </li>
<Li class = "ge" >|</li>

Add a name style to favorites and set it as the homepage code
There are also some basic html code for beginners.
Note: This code is only compatible with IE
1: Implement"
Add to favorites:Copy codeThe Code is as follows: <a href = "javascript: window. external. AddFavorite ('HTTP: // www.baidu.com ', 'Baidu')"> Add to favorites </a>

You only need to change the link and site name to your own site name.
If you want to display a prompt that you want to add to the favorites after clicking the mouse, you only need to change the code:Copy codeThe Code is as follows: <a onmouseover = "window. external. addFavorite ('HTTP: // www.baidu.com ', 'Baidu')" target = _ self href => Add to favorites </a>

----------------------------------
2. Set it as the homepage code (html source code)Copy codeThe Code is as follows: <a style = "cursor: hand" onclick = "this. style. behavior = 'url (# default # homepage )';
This. setHomePage ('HTTP: // www.baidu.com/'); ">

<U> Set as HomePage </u> </a>

1. Text Type:Copy codeThe Code is as follows: <a onclick = "this. style. behavior = 'url (# default # homepage) '; this. setHomePage ('HTTP: // www.baidu.com/'); "href =" # "> set as homepage </a>

Example:
Set as Homepage
2. Button type:Copy codeThe Code is as follows: <input TYPE = "button" VALUE = "set as Homepage" onclick = "this. style. behavior = 'url (# default # homepage) '; this. setHomePage ('HTTP: // www.baidu.com/'); "href =" # ">
When you leave, the system automatically prompts you to set it to the homepage.
<Body onunload = "BASEBody. style. behavior = 'url (# default # homepage) '; if (! (BASEBody. isHomePage
('HTTP: // www.baidu.com/') BASEBody. setHomePage (www.baidu.com//'); ">

-----
----------------
When the page is opened, a window pops up automatically asking if it is set as the homepage
Place the following code between Copy codeThe Code is as follows: <script
Language = "javascript">
Function myhomepage (){
This. homepage. style. behavior = 'url (# default # homepage) '; this. homepage. sethomepage ('HTTP: // www.baidu.com ');
}
</Script>
<P align = "center"> <a href = "http://www.baidu.com/" name = "homepage" onclick = "myhomepage ();"> </a>

Add the following code to <body>:
Onload = "myhomepage ();"
That is: <body onload = "myhomepage ();">
-----------------------
Set the prompt to homepage when you point
Insert the following code into the <body> area:Copy codeThe Code is as follows: <A href = "http://www.baidu.com/" onmouseover = "this. style. behavior = 'url (# default # homepage) '; this. setHomePage ('HTTP: // www.baidu.com/'); "target =" _ blank "> set as homepage </A>

--------------
Disable the current window function
Here, we can first enter the text "Close the window", drag it with the mouse to select it, type "/" in the "Link" input box, and switch to the source
In the code window, type the event-onclick = "javascript: window. close (); return false;" in the Link code ;".
The complete code is: <a href = "/" onclick = "javascript: window. close (); return false;"> close the window </a>
----------------------------------
3. Contact the webmaster to link to an email address:Copy codeThe Code is as follows: <a href = "mailto: baidujishubu@163.com"> email box </a>

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.