Article introduction of Wulin.com (www.vevb.com): The most compatible set as homepage + add to favorites function in history.
I have tested that I did not report an error under ie, but now the reason is unknown, and the page reported an error under ie. I am solving it.
Function description:
Set the page as homepage, add collection function, support ie, ff, chrome, safari, 360 security, qq, Aoyou, Sogou browser, add collection function in compatible mode that is incompatible with 360 rapid browser
Notice:
Although it is compatible here, some browser settings do not support using js to set the page as the homepage and add it to favorites. Users can only manually set these functions in the browser or buttons. The compatibility mentioned here means that when the browser has this setting, js will prompt.
As for the incompatible 360 Speed here, I have a demo here, which is 360's own website. In the compatibility mode of 360 Speed browser, the function of adding favorites is not supported. Its own pages on its own browser do not support this function.
Code:
<!doctype html>
<html>
<head>
<title>Set the page as home page, add collection function, support ie, ff, chrome, safari, 360 security, qq, Aoyou, Sogou browser, incompatible with 360 rapid browser, add collection function</title>
</head>
<body>
<div>
<a href=/>Homepage</a> |
<a onclick=SetHome(window.location) href=javascript:void(0)>Set as homepage</a>
| <a onclick=AddFavorite(window.location,document.title) href=javascript:void(0)>Add to favorites</a>
</div>
<script type=text/javascript language=javascript>
// Add to favorites
function AddFavorite(sURL, sTitle) {
sURL = encodeURI(sURL);
try{
window.external.addFavorite(sURL, sTitle);
}catch(e) {
try{
window.sidebar.addPanel(sTitle, sURL, );
}catch (e) {
alert (If you fail to add to favorites, please use Ctrl+D to add, or manually set it in the browser.);
}
}
}
//Set as homepage
function SetHome(url){
if (document.all) {
document.body.style.behavior='url(#default#homepage)';
document.body.setHomePage(url);
}else{
alert (Hello, your browser does not support the automatic setting of page as home page function, please manually set the page as home page in the browser!);
}
}
</script>
</body>
</html>