当前位置: 代码迷 >> Web前端 >> 常见网页奇效
  详细解决方案

常见网页奇效

热度:88   发布时间:2012-11-23 22:54:33.0
常见网页特效
//num表示要四舍五入的数,v表示要保留的小数位数。
function decimal(num,v)
{
    var vv = Math.pow(10,v);
    return Math.round(num*vv)/vv;
}

复制到剪切板 - 兼容 ie, firefox, chrome & flash10 flash部署到服务器上才可以,不能直接打开页面

防止复制,剪切,粘贴

<body oncopy = " return false "  oncut = " return false "  onpaste = " return false ">

4、禁止查看源码

<body oncontextmenu="return false"></body> 

19、打印

<input type=button value='打印' onClick="window.print();">
 
<script type="text/javascript">  
 <!--
 function prePrint()
{
    if (window.print) window.print();
    else if (VBS) printIt();
    else alert('This script does not work in your browser');
}
-->
</script>
</head>
<body onload="javascript:prePrint();" style="background-color:#FFFFFF;">

20、打印预览

<OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height=0 id=wb name=wb width=0></OBJECT>
<input type=button value=打印预览 onclick="wb.execwb(7,1)"> 

21、另存为

<input onClick="document.execCommand('saveas','true','常用代码.htm')" type=button value=另存为> 

9、彻底屏蔽鼠标右键

?? <body oncontextmenu="window.event.returnValue=false">
?? 或者:<body oncontextmenu="self.event.returnValue=false">
?? 或者:<body oncontextmenu="return false">

?

文本框里禁止自动完成功能,不再出现window自带的提示功能
<input type="text" name="T1" size="20" autocomplete="off">


无关闭按钮IE
window.open("aa.htm", "meizz", "fullscreen=7");
ENTER键可以让光标移到下一个输入框
<input onkeydown="if(event.keyCode==13)event.keyCode=9">

文本框的默认值
<input type=text value="123" onChange="alert(this.defaultValue )">
自动全选
<input type=text name=text1 value="123" onfocus="this.select()">

?

调用方法

<a href="#" title="Siming-Craft" href="http://www.testt.com" onclick="window.external.addFavorite(this.href,this.title);return false;">加入收藏</a>
<a href="#"?onclick="SetHome(this,window.location)">设为首页</a>

function SetHome(obj, vrl) {
    try {
        obj.style.behavior = 'url(#default#homepage)';
        obj.setHomePage(vrl);
    } catch(e) {
        if (window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            } catch(e) {
                alert("此操作被浏览器拒绝!\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。");
            }
            var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
            prefs.setCharPref('browser.startup.homepage', vrl);
        }
    }
}
  相关解决方案