兼容IE5+/Win,Firefox,Netscape6+,Opera7+,Safari,Konqueror3,IE5/Mac,还有iCab3.
复制代码 代码如下:
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<title>addbookmarkcrossallbrowser-http://www.never-online.net</title>
<metahttp-equiv="ImageToolbar"content="no"/>
<metaname="author"content="never-online,BlueDestiny"/>
<metaname="keywords"content="nevermodules,MozillaCSS,C#,.net,Reference,BlueDestiny,never-online"/>
<metaname="description"content="addbookmarkcrossallbrowser,javascriptreference,csharpartilces"/>
<metaname="creator.name"content="never-online,BlueDestiny"/>
<styletype="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:"TrebuchetMS",Verdana,Arial,Helvetica,sans-serif;
}
a{
color:#fff;
}
div#header{
text-align:center;
color:#eee;
}
div#headera{
color:#fff;
font-weight:bold;
}
div#footer{
margin-top:10px;
text-align:center;
color:#eee;
font-size:8pt;
}
div#operator{
margin:20px020px0;
}
div#operatorul,div#operatorli{
margin:0;
padding:0;
}
div#operatorli{
display:inline;
list-style-type:none;
margin-right:5px;
margin-left:5px;
border:1pxsolid#000;
padding:5px;
color:#000;
background-color:#eee;
cursor:hand;
cursor:pointer;
}
hr{
margin:10px010px0;
}
div.wrapper{
text-align:center;
}
div.content{
border:1pxsolid#333;
background-color:buttonface;
color:#000;
padding:10px;
margin:10px010px0;
font-size:10pt;
line-height:150%;
text-align:left;
width:80%;
margin-left:auto;
margin-right:auto;
-moz-box-sizing:border-box;
}
div.contenta{
color:#000;
}
div.contenth4{
color:#000;
margin-left:10px;
text-align:left;
}
</style>
<scripttype="text/javascript">
//<![CDATA[
/*
*Copyright2006DynamicSiteSolutions.
*Freeuseofthisscriptispermittedfornon-commercialapplications,
*subjecttotherequirementthatthiscommentblockbekeptandnotbe
*altered.Thedataandexecutablepartsofthescriptmaybechanged
*asneeded.DynamicSiteSolutionsmakesnowarrantyregardingfitness
*ofuseorcorrectfunctionofthescript.Termsforuseofthisscript
*incommercialapplicationsmaybenegotiated;forthis,orforother
*questions,contact"license-info@dynamicsitesolutions.com".
*
*Scriptby:DynamicSiteSolutions--http://www.dynamicsitesolutions.com/
*LastUpdated:2006-08-03
*/
//IE5+/Win,Firefox,Netscape6+,Opera7+,Safari,Konqueror3,IE5/Mac,iCab3
varaddBookmarkObj={
init:function(){
if(!document.getElementById||!document.createTextNode)return;
varcont=document.getElementById('addBookmarkContainer');
if(!cont)return;
vara=document.createElement('a');
a.href=location.href;
if(!window.opera){//thisdoesn'tworkinOpera7+ifthelinkhasan
//onclickhandler,soweonlyadditifthebrowserisn'tOpera.
a.onclick=function(){
addBookmarkObj.exec(this.href,this.title);
returnfalse;
}
}
a.rel='sidebar';//thismakesitworkinFirefoxandOpera7+
a.title=document.title;
a=cont.appendChild(a);
a.appendChild(document.createTextNode('BookmarkThisPage'));
},
exec:function(url,title){
varisKonq=(isLikelyKonqueror3&&isLikelyKonqueror3());
varisMac=(navigator.userAgent.toLowerCase().indexOf('mac')!=-1);
varbuttonStr=isMac?'Command/Cmd':'CTRL';
if(window.external&&(!document.createTextNode||
(typeof(window.external.AddFavorite)=='unknown'))){
//IE4/Wingeneratesanerrorwhenyou
//execute"typeof(window.external.AddFavorite)"
//InIE7thepagemustbefromwebserver,notdirectlyfromalocal
//filesystem,otherwise,yougetapermissiondeniederror.
window.external.AddFavorite(url,title);//IE/Win
}elseif(isKonq){
alert('YouneedtopressCTRL+Btobookmarkoursite.');
}elseif((window.sidebar&&
(navigator.userAgent.toLowerCase().indexOf('firefox')!=-1))||
(window.opera&&opera.buildNumber&&!isNaN(opera.buildNumber()))){
void(0);//donothinghere(FirefoxorOpera7+)
}elseif(window.opera){//olderOpera
alert('Youneedtopress'+buttonStr+'+Ttobookmarkoursite.');
}elseif(window.home){//Netscape,iCab
alert('Youneedtopress'+buttonStr+'+Dtobookmarkoursite.');
}elseif(!window.print||isMac){//IE5/MacandSafari1.0
alert('YouneedtopressCommand/Cmd+Dtobookmarkoursite.');
}else{
alert('Inordertobookmarkthissiteyouneedtodosomanually'+
'throughyourbrowser.');
}
}
}
functionisLikelyKonqueror3(){
if(!document.getElementById)returnfalse;
if(document.defaultCharset||window.opera||!window.print)returnfalse;
if(window.home)returnfalse;/*Konquerordoesn'tsupportthisbutFirefox,
whichhassilentsupportfordocument.allwheninQuirksModedoes*/
if(document.all)returntrue;//Konquerorversionsbefore3.4
varlikely=1;
//testingforsilentdocument.allsupport;try-catchusedtokeepitfrom
//generatingerrorsinotherbrowsers.
//try-catchcauseserrorsinIE4soweusetheeval()tohideit.
//try{
//varstr=document.all[0].tagName;
//}catch(err){likely=0;}
eval("try{varstr=document.all[0].tagName;}catch(err){likely=0;}");
returnlikely;
}
functiondss_addEvent(el,etype,fn){
if(el.addEventListener&&(!window.opera||opera.version)&&
(etype!='load')){
el.addEventListener(etype,fn,false);
}elseif(el.attachEvent){
el.attachEvent('on'+etype,fn);
}else{
if(typeof(fn)!="function")return;
vartempFunc=el['on'+etype];
el['on'+etype]=function(){
if(typeof(tempFunc)=="function")tempFunc();
fn();
}
}
}
dss_addEvent(window,'load',addBookmarkObj.init);
//]]>
</script>
</head>
<bodyid="www.never-online.net">
<divid="header"><h1>cross-browseraddBookmark</h1>bywww.dynamicsitesolutions.com<hr/></div>
<divclass="wrapper">
<divclass="content">
<h4>demonstration</h4>
<divid="addBookmarkContainer"></div>
</div>
</div>
<divid="footer">collectedby<ahref="http://www.never-online.net">http://www.never-online.net</a></div>
</body>
</html>