Last Updated: January 20, 2020
·
7.826K
· nxqd

Javascript text editor right in your browser in one line of code

Paste the line of code below to your browser's address field. It just works !

data:text/html, <style type="text/css">#js-editor{position:absolute;top:0;right:0;bottom:0;left:0;}</style><div id="js-editor"></div><script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script><script>var jsEditor=ace.edit("js-editor");jsEditor.setTheme("ace/theme/monokai");jsEditor.getSession().setMode("ace/mode/javascript");</script>

Browser compatibility:

  1. Chrome + Chrome Dev + Chrome Canary: works

  2. Safari: works

  3. Firefox: doesn't work

  4. IE: who cares

12 Responses
Add your response

This is super awesome.

over 1 year ago ·

Note that you can change the syntax highlighting and code completion by changing ace/mode/javascript to ace/mode/html or ace/mode/ruby, etc.

over 1 year ago ·

And a guide on how to customize it further: http://ace.c9.io/#nav=howto

over 1 year ago ·

@anthropomorphic: thanks for your comment. Actually I thought about writing a script that prompt user to write the language they want to be highlighted. But it ruins the whole point of something that just works and discovery of the script :P

over 1 year ago ·

I agree entirely. However it is good to know how versatile it can be. I coppied it, reduced the indent to two, set language to ruby, removed the page guide and made a gist. Now I have a ruby editor at a moments notice. Super useful in my opinion. And apparently you can include preset text, disable editing and embed it in a page. Fast, easy sharing of code snippets with syntax highlighting and line numbers.

over 1 year ago ·

I'm glad that you like it :D

over 1 year ago ·

Is there any way to have the JavaScript code evaluated? Would be a great minimalistic alternative to JSFiddle.

over 1 year ago ·

@rwilhelm: very nice idea actually :D

over 1 year ago ·

Great tip Dung. I am guessing that it is possible to modify the syntax highlighting so that it works with other languages by modifying the setting in this line?

jsEditor.getSession().setMode("ace/mode/javascript")
over 1 year ago ·

Gr8 work...

over 1 year ago ·

super awesome

over 1 year ago ·

@chrissimpkins: yes, you can :)

over 1 year ago ·