Set as homepage and add to favorites

Source: Internet
Author: User

Set as homepage and add favoritesCode, Can be seen everywhere, find the website, ViewSource codeThat's all. It's generally implemented in Js ..

Code <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< Html Xmlns = "Http://www.w3.org/1999/xhtml" >
< Head >
< Meta HTTP-equiv = "Content-Type" Content = "Text/html; charset = gb2312"   />
< Title > 9421 Test </ Title >
</ Head >
< Body >

< Script Type = "Text/JavaScript" >
Function SetHomePage (){ // Set Homepage
If (Document. All ){
Document. Body. style. Behavior = ' URL (# default # homepage) ' ;
Document. Body. setHomePage ( ' Http://www.9421.org ' );
}

Else   If (Window. Sidebar ){
If (Window. Netscape ){
Try {
Netscape. Security. privilegemanager. enableprivilege ( " Universalxpconnect " );
}
Catch (E ){
Alert ( " The [set as homepage] function is not enabled in your browser. Enable this function: Enter about: config in the address bar, and set the value of signed. Applets. codebase_principal_support to true. " );
}
}
VaR Prefs = Components. classes [ ' @ Mozilla.org/preferences-service=1 ' ]. Getservice (components. Interfaces. nsiprefbranch );
Prefs. setcharpref ( ' Browser. startup. Homepage ' , ' Http://www.9421.org ' );
Alert ( " The settings are complete! " );
}
}

Function Addcookie (){ // Add to favorites
If (Document. All ){
Window. External. AddFavorite ( ' Http://www.56beijing.org ' , ' 9421 Test ' );
}
Else   If (Window. Sidebar ){
Window. Sidebar. addpanel ( ' 9421 Test ' , ' Http://www.9421.org ' , "" );
}
}
</ Script >  
 
< A Onclick = "Javascript: setHomePage ();" Href = "#" > Set homepage | </ A >  
< A Href = "#" Onclick = "Javascript: addcookie ();" > Add to favorites </ A >

</ Body >
</ Html >

Key code:

Document. Body. setHomePage ('HTTP: // www.9421.org ');

/// Var prefs = components. classes ['@ mozilla.org/preferences-service%1'}.getservice (components. Interfaces. nsiprefbranch );
/// Prefs. setcharpref ('browser. startup. homepage', 'HTTP: // www.9421.org ');

Window. External. AddFavorite ('HTTP: // www.56beijing.org ', '9421test ');

/// Window. Sidebar. addpanel ('9421test', 'HTTP: // www.9421.org ',"");

Browser judgment:

If (document. all) {
window. external. addFavorite ('HTTP: // www.56beijing.org ', '9421test');
}< br> else if (window. sidebar) {
window. sidebar. addpanel ('9421test', 'HTTP: // www.9421.org ', "");
}

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.