Perfect compatible IE,CHROME,FF homepage, add favorites and save to desktop JS code _javascript Tips

Source: Internet
Author: User

Today to share a section set for the home page, the collection site and save to the desktop JS code, very practical.

Copy Code code as follows:

<script type= "Text/javascript" >
Set as homepage
function Sethome (obj,url) {
try{
Obj.style.behavior= ' url (#default #homepage) ';
Obj.sethomepage (URL);
}catch (e) {
if (Window.netscape) {
try{
Netscape.security.PrivilegeManager.enablePrivilege ("Universalxpconnect");
}catch (e) {
Alert ("Sorry, this operation is rejected by the browser!") \ n \ nplease enter "About:config" in the browser address bar and return to the [Signed.applets.codebase_principal_support] setting to ' true ');
}
}else{
Alert ("Sorry, the browser you are using cannot complete this operation.") \ n \ nyou need to manually set "+url+" as the home page. ");
}
}
}
Collect this site
function addfavorite (title, URL) {
try {
Window.external.addFavorite (URL, title);
}
catch (e) {
try {
Window.sidebar.addPanel (title, URL, "");
}
catch (e) {
Alert ("Sorry, the browser you are using cannot complete this operation.") \ n \ nyou failed to join the collection, please use Ctrl+d to add ");
}
}
}
Save to Desktop
function Todesktop (surl,sname) {
try {
var WshShell = new ActiveXObject ("Wscript.Shell");
var ourllink = wshshell.createshortcut (Wshshell.specialfolders ("Desktop") + "\" + sname + ". url");
Ourllink.targetpath = sURL;
Ourllink.save ();
}
catch (e) {
Alert ("Current IE security level does not allow operation!") ");
}
}
</script>

Page calls:

Copy Code code as follows:

<a href= "javascript:void (0);" onclick= "sethome (This, ' http://www.xyz.com ');" > Homepage </a>
<a href= "javascript:void (0);" onclick= "Addfavorite (' My website ', Location.href)" > Favorites Site </a>
<a href= "javascript:void (0);" onclick= "Todesktop (location.href, ' My Site ')" > Save to Desktop </a>

This is from my website to peel down drops, everybody rest assured use.

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.