javascript - How do I make a link using keybindins, and selected text -


i looking way ctrl-l, popups box to insert link, on selected text. stackexchange editor, i'm using right now!

the links preferably valid html, , if can choose both markdown , valid html, awesome!

i not find anywhere on so, or interwebs.

what have done before:

$("#mark").click(function () {    var range = window.getselection().getrangeat(0);    var newnode = document.createelement('mark');    range.surroundcontents(newnode);        return false;   }); 

button:

<a href="javascript:void(0)" id="mark">mark</a> 

when clicking mark button apply html mark tag

<mark>selected text</mark>

i want same feaute stackexchange editor:ctrl-lget box:

enter image description here


edit

my new code :

while playing promptbox using javascript[1], managed way want it.

<button onclick="link()">link</button>  <p id="demo"></p>  <script> function link() {     var link = prompt("insert hyperlink", "http://");     var title = prompt("insert hyperlink title", "title");     var name = prompt("insert hyperlink name", "name");      if (link != null) {         document.getelementbyid("demo").innerhtml =         "\<a href=\"" + link + "\" title=\" " + title + " \"> " + name + " </a>";     } } </script> 

jsfiddle

trying work:

  • to content of html title tag, when inserting link.

    example:

    <a href="https://www.example.nl/example" title="*link*: *title*">*title*</a>

reference:

  1. tryit editor v2.2

using jquery, can use on keydown trigger capture keys pressed, :

$('#your_textarea').on('keydown', function(e){     //check if ctrl-l     if(e.keycode == 76 && e.ctrlkey)     {         var link = prompt("enter link : ");     } }); 

now, link user entered in linkvariable. can want (ex: append editor's textarea).

note : have use keydownevent, keypressedand keyupevents not work this.

here's fiddle : http://jsfiddle.net/js1p5h9n/


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

xcode - Swift Playground - Files are not readable -

jboss7.x - JBoss AS 7.3 vs 7.4 and differences -