Set Homepage Favorites compatible with Firefox/Google/ie and other mainstream browser code _javascript tips

Source: Internet
Author: User
Tags button type
No need to find, I tried many times, ie, Firefox, Google browser This code is irreversible compatibility.
Here's my simple solution. The way to solve this problem completely is to create an action step help page that adds the homepage as well as other major websites.

JS Code:
Copy Code code as follows:

<script type= "Text/javascript" >
Set as 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!") \ nplease type "About:config" in the browser address bar and enter \ n then set the value of [Signed.applets.codebase_principal_support] to ' true ' and double-click. ");
}
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, follow these steps: 1." Open browser settings.) 2. Click the Settings page. 3. Input: "+vrl+" click OK. ");
}
}
}
Add to Favorites Compatibility 360 and IE6
function Shoucang (Stitle,surl)
{
Try
{
Window.external.addFavorite (sURL, stitle);
}
catch (E)
{
Try
{
Window.sidebar.addPanel (Stitle, sURL, "");
}
catch (E)
{
Alert ("Join collection failed, please use Ctrl+d to add");
}
}
}
</script>

Calling code:
Copy Code code as follows:

<li class= "Fore1" ><a href= "javascript:void (0)" onclick= "Sethome (this,window.location)" > Set as 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>

Favorites and set as home code for the name style
There are some of the most basic HTML code, only for beginners to refer to.
Note: This code is only compatible with IE browser
1: Realize "
The code for the Add Favorites feature is as follows:
Copy Code code as follows:

<a href= "Javascript:window.external.AddFavorite (' http://www.baidu.com ', ' Baidu ')" > Add Favorites </a>

You can simply change the link and station name to your own station name.
If you want to implement the mouse when you are prompted to join the collection, simply change the code to:
Copy Code code as follows:

<a onmouseover= "Window.external.addFavorite (' http://www.baidu.com ', ' Baidu ')" Target=_self href= > Add Favorites </a>

----------------------------------
2. Set homepage code (HTML source)
Copy Code code 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 Code code as follows:

< a onclick= "this.style.behavior= ' url (#default #homepage) '; This.sethomepage (' http://www.baidu.com/');" href= " > Homepage </a>

Example:
Set as homepage
2. Button Type:
Copy Code code as follows:

< input type= "button" value= "Set as homepage" onclick= "this.style.behavior= ' url (#default #homepage) '; This.sethomepage (' http ://www.baidu.com/'); "href=" >
Automatically prompt to set as home page when leaving
<body onunload= "basebody.style.behavior=" url (#default #homepage) '; Basebody.ishomepage
(' http://www.baidu.com/')) Basebody.sethomepage (www.baidu.com//'); " >

—————
———————————————-
Automatically pop-up window when opening page to ask whether to set the homepage
Place the following code between
Copy Code code 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 the <body>:
Onload= "Myhomepage ();"
namely: <body onload= "myhomepage ();" >
——————————————————————–
Prompt when pointing to the mouse to set as the home page
Insert the following code into the <body> area:
Copy Code code as follows:

<a href= "http://www.baidu.com/" onmouseover = "this.style.behavior=" url (#default #homepage) '; This.sethomepage (' http://www.baidu.com/'); "Target=" _blank > Set homepage </A>

—————————————–
To close the current window's functionality
Here we can first enter the text to be labeled "Close the Window", drag the mouse to select it, in the "Link" input box type "/", while cutting into the source generation
Code window, type the event in the link Code-onclick= "Javascript:window.close (); return false; ".
The complete code for:< a href= "/" onclick= "javascript:window.close (); return false; > Close Window </a>
----------------------------------
3. Contact webmaster words is actually linked to an e-mail address:
Copy Code code as follows:

<a href= "mailto:baidujishubu@163.com" > Email </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.