web前端经常使用技术点001

前言

本文主要总结了一些线上文档的实用技术,后面陆续会根据实际需求将不一样的技术进行分类或者归到兼容文档里。javascript

技术点以下

屏蔽鼠标右键

方案:oncontextmenu=”window.event.returnValue=false”html

取消选取、防止复制

方案:onselectstart=”return false”前端

JS不容许粘贴

方案:onpaste=”return false”java

JS防止复制

方案:oncopy=”return false;” oncut=”return false;”web

能够在收藏夹中显示出你的图标

方案:< link rel=”Bookmark” href=”favicon.ico”>ajax

关闭输入法

方案:< input style=”ime-mode:disabled”>浏览器

防止被人 frame

方案:缓存

< script >
if (top.location != self.location)top.location=self.location;
< /script>
复制代码

网页将不能被另存为

方案:< noscript>< iframe src=*.html>< /iframe>< /noscript>bash

查看网页源代码

方案:< input type=button value=查看网页源代码 onclick=”window.location = “view-source:”+ “www.pconline.com.cn””>服务器

光标是停在文本框文字的最后

方案:

< script language=”javascript”>
function cc()
{
var e = event.srcElement;
var r =e.createTextRange();
r.moveStart(“character”,e.value.length);
r.collapse(true);
r.select();
}
< /script>
< input type=text name=text1 value=”123″ onfocus=”cc()”>
复制代码

网页不会被缓存

方案:

< META HTTP-EQUIV=”pragma” CONTENT=”no-cache”>
< META HTTP-EQUIV=”Cache-Control” CONTENT=”no-cache, must-revalidate”>
< META HTTP-EQUIV=”expires” CONTENT=”Wed, 26 Feb 1997 08:21:57 GMT”>
或者< META HTTP-EQUIV=”expires” CONTENT=”0″>
复制代码

怎样去掉图片连接点击后,图片周围的虚线

方案:< a href=”#” onFocus=”this.blur()”>< img src=”logo.jpg” border=0>< /a>

如何设定打开页面的大小

方案:

< body onload=”top.resizeTo(300,200);”>
//打开页面的位置
< body onload=”top.moveBy(300,200);”>
复制代码

ENTER 键能够让光标移到下一个输入框

方案:< input onkeydown=”if(event.keyCode==13)event.keyCode=9″>

各类样式的光标

方案: auto :标准光标 ;default :标准箭头 ; hand :手形光标; wait :等待光标; text :I 形光标; vertical-text :水平; I 形光标; no-drop :不可拖动光标 ; not-allowed :无效光标 ; help :?帮助光标 ; all-scroll :三角方向标; move :移动标; crosshair :十字标;其余: e-resize n-resize nw-resize w-resize s-resize se-resize sw-resize

在规定时间内跳转

方案:< META http-equiv=V=”REFRESH” content=”5;URL=http://www.51js.com”>

将完全屏蔽鼠标右键

方案:oncontextmenu=”window.event.returnValue=false”

ie与其余浏览器的区别

解析:在获取属性,ajax请求,事件坐标,透明的写法,阻止冒泡等均是不一样的。 参考资料:ie与其余浏览器区别

web应用向前端推送数据的方式

  • js
  • Commet:基于HTTP长链接的服务器推送技术
  • 基于WebSocket的推送方案
  • SSE(Server-Send Event):服务器推送数据新方式 方案:oncontextmenu=”window.event.returnValue=false”

实现文本缩进

方案:text-indent 能够实现文本的缩进

将完全屏蔽鼠标右键

方案:oncontextmenu=”window.event.returnValue=false”

java根据html代码生成pdf文件

方案:参考代码

public void createPdf() throws Exception {  
        // step 1  
        String inputFile = "index.html";  
        String url = new File(inputFile).toURI().toURL().toString();  
        String outputFile = "index.pdf";  
        System.out.println(url);  
        // step 2  
        OutputStream os = new FileOutputStream(outputFile);  
        org.xhtmlrenderer.pdf.ITextRenderer renderer = new ITextRenderer();  
        renderer.setDocument(url);  
  
        // step 3 解决中文支持  
        org.xhtmlrenderer.pdf.ITextFontResolver fontResolver = renderer  
                .getFontResolver();  
        fontResolver.addFont("c:/Windows/Fonts/simsun.ttc", BaseFont.IDENTITY_H,     
                BaseFont.NOT_EMBEDDED);  
  
        renderer.layout();  
        renderer.createPDF(os);  
        os.close();  
          
        System.out.println("create pdf done!!");  
    }  
       
复制代码

加载https协议的文件

你们在使用原始方式载入脚本或者样式文件的时候,通常cdn的建议方式是https的,但咱们的应用协议不必定是https的,这种时候使用// ,会自动识别当前页面适合的协议,若是你强行使用https就会报错或者很慢

参考文档

相关文章
相关标签/搜索