添加到收藏夹代码(兼容几乎所有的浏览器)
程序员文章站
2022-10-09 10:56:43
兼容ie5+/win, firefox, netscape 6+, opera 7+, safari, ...
兼容ie5+/win, firefox, netscape 6+, opera 7+, safari, konqueror 3, ie5/mac, 还有 icab 3.
<!doctype html public "-//w3c//dtd xhtml 1.0 strict//en"
"http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> addbookmark cross all browser - http://www.never-online.net </title>
<meta http-equiv="imagetoolbar" content="no" />
<meta name="author" content="never-online, bluedestiny"/>
<meta name="keywords" content="never modules, mozilla css, c#, .net, reference, bluedestiny, never-online"/>
<meta name="description" content="addbookmark cross all browser, javascript reference, c sharp artilces"/>
<meta name="creator.name" content="never-online, bluedestiny" />
<style type="text/css" media="all" title="default">
body {
color: windowtext;
background: appworkspace;
font-family: arial;
font-size:9pt;
line-height:150%;
}
h1, h2, h3, h4 {
color:#fff;
font-family: "trebuchet ms",verdana, arial, helvetica, sans-serif;
}
a {
color:#fff;
}
div#header {
text-align:center;
color:#eee;
}
div#header a {
color:#fff;
font-weight:bold;
}
div#footer {
margin-top:10px;
text-align:center;
color:#eee;
font-size:8pt;
}
div#operator {
margin:20px 0 20px 0;
}
div#operator ul, div#operator li {
margin:0;
padding:0;
}
div#operator li {
display:inline;
list-style-type:none;
margin-right:5px;
margin-left:5px;
border:1px solid #000;
padding:5px;
color:#000;
background-color:#eee;
cursor:hand;
cursor:pointer;
}
hr {
margin:10px 0 10px 0;
}
div.wrapper {
text-align:center;
}
div.content {
border:1px solid #333;
background-color:buttonface;
color:#000;
padding:10px;
margin:10px 0 10px 0;
font-size:10pt;
line-height:150%;
text-align:left;
width:80%;
margin-left: auto;
margin-right: auto;
-moz-box-sizing:border-box;
}
div.content a {
color:#000;
}
div.content h4 {
color:#000;
margin-left:10px;
text-align:left;
}
</style>
<script type="text/javascript">
//<![cdata[
/*
* copyright 2006 dynamic site solutions.
* free use of this script is permitted for non-commercial applications,
* subject to the requirement that this comment block be kept and not be
* altered. the data and executable parts of the script may be changed
* as needed. dynamic site solutions makes no warranty regarding fitness
* of use or correct function of the script. terms for use of this script
* in commercial applications may be negotiated; for this, or for other
* questions, contact "license-info@dynamicsitesolutions.com".
*
* script by: dynamic site solutions -- http://www.dynamicsitesolutions.com/
* last updated: 2006-08-03
*/
//ie5+/win, firefox, netscape 6+, opera 7+, safari, konqueror 3, ie5/mac, icab 3
var addbookmarkobj = {
init:function() {
if(!document.getelementbyid || !document.createtextnode) return;
var cont=document.getelementbyid('addbookmarkcontainer');
if(!cont) return;
var a=document.createelement('a');
a.href=location.href;
if(!window.opera) { // this doesn't work in opera 7+ if the link has an
// onclick handler, so we only add it if the browser isn't opera.
a.onclick=function() {
addbookmarkobj.exec(this.href,this.title);
return false;
}
}
a.rel='sidebar'; // this makes it work in firefox and opera 7+
a.title=document.title;
a=cont.appendchild(a);
a.appendchild(document.createtextnode('bookmark this page'));
},
exec:function(url, title) {
var iskonq=(islikelykonqueror3 && islikelykonqueror3());
var ismac=(navigator.useragent.tolowercase().indexof('mac')!=-1);
var buttonstr = ismac?'command/cmd':'ctrl';
if(window.external && (!document.createtextnode ||
(typeof(window.external.addfavorite)=='unknown'))) {
// ie4/win generates an error when you
// execute "typeof(window.external.addfavorite)"
// in ie7 the page must be from web server, not directly from a local
// file system, otherwise, you get a permission denied error.
window.external.addfavorite(url, title); // ie/win
} else if(iskonq) {
alert('you need to press ctrl + b to bookmark our site.');
} else if((window.sidebar &&
(navigator.useragent.tolowercase().indexof('firefox')!=-1)) ||
(window.opera && opera.buildnumber && !isnan(opera.buildnumber()))) {
void(0); // do nothing here (firefox or opera 7+)
} else if(window.opera) { // older opera
alert('you need to press '+buttonstr+' + t to bookmark our site.');
} else if(window.home) { // netscape, icab
alert('you need to press '+buttonstr+' + d to bookmark our site.');
} else if(!window.print || ismac) { // ie5/mac and safari 1.0
alert('you need to press command/cmd + d to bookmark our site.');
} else {
alert('in order to bookmark this site you need to do so manually '+
'through your browser.');
}
}
}
function islikelykonqueror3() {
if(!document.getelementbyid) return false;
if(document.defaultcharset || window.opera || !window.print) return false;
if(window.home) return false; /* konqueror doesn't support this but firefox,
which has silent support for document.all when in quirks mode does */
if(document.all) return true; // konqueror versions before 3.4
var likely = 1;
// testing for silent document.all support; try-catch used to keep it from
// generating errors in other browsers.
// try-catch causes errors in ie4 so we use the eval() to hide it.
// try {
// var str=document.all[0].tagname;
// } catch(err) { likely=0; }
eval("try{var str=document.all[0].tagname;}catch(err){likely=0;}");
return likely;
}
function dss_addevent(el,etype,fn) {
if(el.addeventlistener && (!window.opera || opera.version) &&
(etype!='load')) {
el.addeventlistener(etype,fn,false);
} else if(el.attachevent) {
el.attachevent('on'+etype,fn);
} else {
if(typeof(fn) != "function") return;
var tempfunc = el['on'+etype];
el['on'+etype] = function() {
if(typeof(tempfunc) == "function") tempfunc();
fn();
}
}
}
dss_addevent(window,'load',addbookmarkobj.init);
//]]>
</script>
</head>
<body id="www.never-online.net">
<div id="header"><h1> cross-browser addbookmark </h1>by www.dynamicsitesolutions.com<hr/></div>
<div class="wrapper">
<div class="content">
<h4> demonstration </h4>
<div id="addbookmarkcontainer"></div>
</div>
</div>
<div id="footer">collected by <a href="http://www.never-online.net">http://www.never-online.net</a></div>
</body>
</html>
复制代码 代码如下:
<!doctype html public "-//w3c//dtd xhtml 1.0 strict//en"
"http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> addbookmark cross all browser - http://www.never-online.net </title>
<meta http-equiv="imagetoolbar" content="no" />
<meta name="author" content="never-online, bluedestiny"/>
<meta name="keywords" content="never modules, mozilla css, c#, .net, reference, bluedestiny, never-online"/>
<meta name="description" content="addbookmark cross all browser, javascript reference, c sharp artilces"/>
<meta name="creator.name" content="never-online, bluedestiny" />
<style type="text/css" media="all" title="default">
body {
color: windowtext;
background: appworkspace;
font-family: arial;
font-size:9pt;
line-height:150%;
}
h1, h2, h3, h4 {
color:#fff;
font-family: "trebuchet ms",verdana, arial, helvetica, sans-serif;
}
a {
color:#fff;
}
div#header {
text-align:center;
color:#eee;
}
div#header a {
color:#fff;
font-weight:bold;
}
div#footer {
margin-top:10px;
text-align:center;
color:#eee;
font-size:8pt;
}
div#operator {
margin:20px 0 20px 0;
}
div#operator ul, div#operator li {
margin:0;
padding:0;
}
div#operator li {
display:inline;
list-style-type:none;
margin-right:5px;
margin-left:5px;
border:1px solid #000;
padding:5px;
color:#000;
background-color:#eee;
cursor:hand;
cursor:pointer;
}
hr {
margin:10px 0 10px 0;
}
div.wrapper {
text-align:center;
}
div.content {
border:1px solid #333;
background-color:buttonface;
color:#000;
padding:10px;
margin:10px 0 10px 0;
font-size:10pt;
line-height:150%;
text-align:left;
width:80%;
margin-left: auto;
margin-right: auto;
-moz-box-sizing:border-box;
}
div.content a {
color:#000;
}
div.content h4 {
color:#000;
margin-left:10px;
text-align:left;
}
</style>
<script type="text/javascript">
//<![cdata[
/*
* copyright 2006 dynamic site solutions.
* free use of this script is permitted for non-commercial applications,
* subject to the requirement that this comment block be kept and not be
* altered. the data and executable parts of the script may be changed
* as needed. dynamic site solutions makes no warranty regarding fitness
* of use or correct function of the script. terms for use of this script
* in commercial applications may be negotiated; for this, or for other
* questions, contact "license-info@dynamicsitesolutions.com".
*
* script by: dynamic site solutions -- http://www.dynamicsitesolutions.com/
* last updated: 2006-08-03
*/
//ie5+/win, firefox, netscape 6+, opera 7+, safari, konqueror 3, ie5/mac, icab 3
var addbookmarkobj = {
init:function() {
if(!document.getelementbyid || !document.createtextnode) return;
var cont=document.getelementbyid('addbookmarkcontainer');
if(!cont) return;
var a=document.createelement('a');
a.href=location.href;
if(!window.opera) { // this doesn't work in opera 7+ if the link has an
// onclick handler, so we only add it if the browser isn't opera.
a.onclick=function() {
addbookmarkobj.exec(this.href,this.title);
return false;
}
}
a.rel='sidebar'; // this makes it work in firefox and opera 7+
a.title=document.title;
a=cont.appendchild(a);
a.appendchild(document.createtextnode('bookmark this page'));
},
exec:function(url, title) {
var iskonq=(islikelykonqueror3 && islikelykonqueror3());
var ismac=(navigator.useragent.tolowercase().indexof('mac')!=-1);
var buttonstr = ismac?'command/cmd':'ctrl';
if(window.external && (!document.createtextnode ||
(typeof(window.external.addfavorite)=='unknown'))) {
// ie4/win generates an error when you
// execute "typeof(window.external.addfavorite)"
// in ie7 the page must be from web server, not directly from a local
// file system, otherwise, you get a permission denied error.
window.external.addfavorite(url, title); // ie/win
} else if(iskonq) {
alert('you need to press ctrl + b to bookmark our site.');
} else if((window.sidebar &&
(navigator.useragent.tolowercase().indexof('firefox')!=-1)) ||
(window.opera && opera.buildnumber && !isnan(opera.buildnumber()))) {
void(0); // do nothing here (firefox or opera 7+)
} else if(window.opera) { // older opera
alert('you need to press '+buttonstr+' + t to bookmark our site.');
} else if(window.home) { // netscape, icab
alert('you need to press '+buttonstr+' + d to bookmark our site.');
} else if(!window.print || ismac) { // ie5/mac and safari 1.0
alert('you need to press command/cmd + d to bookmark our site.');
} else {
alert('in order to bookmark this site you need to do so manually '+
'through your browser.');
}
}
}
function islikelykonqueror3() {
if(!document.getelementbyid) return false;
if(document.defaultcharset || window.opera || !window.print) return false;
if(window.home) return false; /* konqueror doesn't support this but firefox,
which has silent support for document.all when in quirks mode does */
if(document.all) return true; // konqueror versions before 3.4
var likely = 1;
// testing for silent document.all support; try-catch used to keep it from
// generating errors in other browsers.
// try-catch causes errors in ie4 so we use the eval() to hide it.
// try {
// var str=document.all[0].tagname;
// } catch(err) { likely=0; }
eval("try{var str=document.all[0].tagname;}catch(err){likely=0;}");
return likely;
}
function dss_addevent(el,etype,fn) {
if(el.addeventlistener && (!window.opera || opera.version) &&
(etype!='load')) {
el.addeventlistener(etype,fn,false);
} else if(el.attachevent) {
el.attachevent('on'+etype,fn);
} else {
if(typeof(fn) != "function") return;
var tempfunc = el['on'+etype];
el['on'+etype] = function() {
if(typeof(tempfunc) == "function") tempfunc();
fn();
}
}
}
dss_addevent(window,'load',addbookmarkobj.init);
//]]>
</script>
</head>
<body id="www.never-online.net">
<div id="header"><h1> cross-browser addbookmark </h1>by www.dynamicsitesolutions.com<hr/></div>
<div class="wrapper">
<div class="content">
<h4> demonstration </h4>
<div id="addbookmarkcontainer"></div>
</div>
</div>
<div id="footer">collected by <a href="http://www.never-online.net">http://www.never-online.net</a></div>
</body>
</html>
上一篇: 面疙瘩怎么做最好吃,教你做最细腻的面疙瘩