道招

一行代码,轻松将浏览器变成临时编辑器

如果您发现本文排版有问题,可以先点击下面的链接切换至老版进行查看!!!

一行代码,轻松将浏览器变成临时编辑器

这是 Jose 在CoderWall 分享的一个小技巧:在浏览器地址栏中输入一行代码: [code lang="php"]data:text/html, &lt;html contenteditable[/code], 回车即可把浏览器变临时编辑器。 为什么它能奏效? 这是用了数据URI的格式(Data URI’s format),并告诉浏览器渲染 HTML。不过 contenteditable 是 HTML5 的一个新全局属性,所以这个小技巧只能用于支持该属性的现代浏览器。(IE 8 – 就不行了 :( ) test in IE 8 并非只能纯文字,也可粘贴图片(如下图)。赶紧复制粘贴那行代码,然后回车,来试试呗。 test in Comodo 有趣的内容还在下面 不少程序员受 Jose 的启发,开始对这行代码加工改造了。 ● jakeonrails 童鞋改成了一个支持 Ruby 代码高亮的编辑器  https://gist.github.com/4666256 test in Chrome 24 代码: [code lang="php"] data:text/html, <style type="text/css">#e{position:absolute;top:0;right:0;bottom:0;left:0;}</style><div id="e"></div><script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script><script>var e=ace.edit("e");e.setTheme("ace/theme/monokai");e.getSession().setMode("ace/mode/ruby");</script> [/code] ● slawdan 提示说:如果把上面的 ace/mode/ruby 改成 ace/mode/python,那么就得到了一个 Python 版的编辑器咯。其他语言依此类推。 ● jdkanani 后来的补充:(2013-1-30 22:06:48 更新) [code] 改造成支持其他语言语法高亮的,可把 ace/mode/ruby 替换为: Python -> ace/mode/python C/C++ -> ace/mode/c_cpp Javscript -> ace/mode/javascript Java -> ace/mode/java Scala -> ace/mode/scala Markdown -> ace/mode/markdown CoffeeScript -> ace/mode/coffee 其他…… jakeonrails 语法高亮风格用的是 monokai。 如果需要换成其他风格,,可把 ace/theme/monokai 替换为: Eclipse -> ace/theme/eclipse TextMate -> ace/theme/textmate 其他…… [/code] 不想复制粘贴代码的懒汉童鞋,可以直接戳下面这些链接Ruby 编辑器 、Python 编辑器PHP 编辑器 、Javascript 编辑器 、Java 编辑器 、C/C++ 编辑器 (也可把这些链接作为浏览器书签收藏哦。) ● montas 的改造:You can use textarea and make it “invisible” if you want autofocus. [code lang="php"] data:text/html, <textarea style="font-size: 1.5em; width: 100%; height: 100%; border: none; outline: none" autofocus /> [/code] 或直接戳 链接。 ● bgrins 的改造:编辑内容时,自动变换背景颜色;停止后变换白色。 [code lang="php"] data:text/html, <html><head><link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'><style type="text/css"> html { font-family: "Open Sans" } * { -webkit-transition: all linear 1s; }</style><script>window.onload=function(){var e=false;var t=0;setInterval(function(){if(!e){t=Math.round(Math.max(0,t-Math.max(t/3,1)))}var n=(255-t*2).toString(16);document.body.style.backgroundColor="#ff"+n+""+n},1e3);var n=null;document.onkeydown=function(){t=Math.min(128,t+2);e=true;clearTimeout(n);n=setTimeout(function(){e=false},1500)}}</script></head><body contenteditable style="font-size:2rem;line-height:1.4;max-width:60rem;margin:0 auto;padding:4rem;"> [/code] ● fvsch 的改造: [code lang="php"] data:text/html, <body contenteditable style="font-size:2rem;line-height:1.4;max-width:60rem;margin:0 auto;padding:4rem;"> [/code] 或直接戳 链接。 这些个奇淫技巧就到此为止吧。 转载自:伯乐在线
更新时间:
上一篇:下一篇:

相关文章

关注道招网公众帐号
友情链接
消息推送
道招网关注互联网,分享IT资讯,前沿科技、编程技术,是否允许文章更新后推送通知消息。
允许
不用了