|
楼主 |
发表于 2011-12-8 10:46:32
|
显示全部楼层
来自 中国–江苏–南京
24.通用的加入收藏夹代码
<script type="text/javascript">
// <![CDATA[
function bookmark(){
var title=document.title
var url=document.location.href
if (window.sidebar) window.sidebar.addPanel(title, url,"");
else if( window.opera && window.print ){
var mbm = document.createElement('a');
mbm.setAttribute('rel','sidebar');
mbm.setAttribute('href',url);
mbm.setAttribute('title',title);
mbm.click();}
else if( document.all ) window.external.AddFavorite( url, title);
}
// ]]>
</script>
<a href="javascript:bookmark()">加入收藏夹</a>
注释:经常有朋友说他的加入收藏夹代码只支持IE,上面的例子可以很好的解决这个问题,在IE6-7. FF2.0 OP9.0中测试通过
25.复制到系统剪贴板之IE,ff兼容版
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<script type="text/javascript">
// <![CDATA[
function copy_clip(copy){
if (window.clipboardData){
window.clipboardData.setData("Text", copy);}
else if (window.netscape){
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
if (!clip) return;
var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
if (!trans) return;
trans.addDataFlavor('text/unicode');
var str = new Object();
var len = new Object();
var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
var copytext=copy;
str.data=copytext;
trans.setTransferData("text/unicode",str,copytext.length*2);
var clipid=Components.interfaces.nsIClipboard;
if (!clip) return false;
clip.setData(trans,null,clipid.kGlobalClipboard);}
alert("已复制"+copy)
return false;
}
// ]]>
</script>
<h1>请另存代码测试</h1>
<input type="text" id="ff" value="www.blueidea.com" /><button>复制
</button>
26.javascript为FF设置首页
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<script type="text/javascript">
// <![CDATA[
function setHomePage(){
if(window.netscape){
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
}
catch (e) {}}
var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
prefs.setCharPref('browser.startup.homepage','http://www.blueidea.com');
}
// ]]>
</script>
<a href="#">设置首页</a>
27.IE6使用滤镜使PNG图片透明后,容器内链接失效的问题。
<!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" xml:lang="zh" lang="zh">
<head profile="http://www.w3.org/2000/08/w3c-synd/#">
<meta http-equiv="content-language" content="zh-cn" />
<meta http-equiv="content-type" content="text/html;charset=gb2312" />
<title>blueidea</title>
<style type="text/css">
/*<![CDATA[*/
div {
width:401px;
height:223px;
filter:progidXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale', src='http://bbs.blueidea.com/attachments/2006/9/11/bg_nT9Vi2i45To0.png')
}
/*]]>*/
</style>
</head>
<body>
<div><a href="#">27.IE6使用滤镜使PNG图片透明后,容器内链接失效的问题。</a></div>
</body>
</html>
注释:解决方法是为链接定义一个相对定位属性。position:relative
28.禁用文本框中文输入法的通用方法。
<div>验证码<input type="text" style="ime-mode:disabled"/></div>
注释:IE可以用ime-mode:disabled,firefox3也开始支持IE的这一私有属性
<!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" xml:lang="zh" lang="zh">
<head profile="http://www.w3.org/2000/08/w3c-synd/#">
<meta http-equiv="content-language" content="zh-cn" />
<meta http-equiv="content-type" content="text/html;charset=gb2312" />
<title>blueidea</title>
<style type="text/css">
/*<![CDATA[*/
input,textarea {
width:300px;
height:20px;
border:1px solid
}
textarea {
height:150px
}
#pw {
opacity:0;
display:block;
position:relative;
margin-top:-24px
}
#tt,#pw {
width:100px
}
/*]]>*/
</style>
</head>
<body>
<table>
<tr>
<td>标题</td>
<td><input type="text"/></td>
</tr>
<tr>
<td>内容</td>
<td><textarea></textarea></td>
</tr>
<tr>
<td>验证码</td>
<td><input type="text" id="tt"/><input type="password" id="pw"/></td>
</tr>
</table>
<script type="text/javascript">
// <![CDATA[
var ee = document.getElementById('pw');
ee.onkeyup = function p() {
document.getElementById('tt').value = ee.value;
}
// ]]>
</script>
</body>
</html>
注释:对于其他不支持的浏览器可以用如下方法模拟
|
|