Jump to content

creatLink in execCommand()


alzami

Recommended Posts

i want to creat link using selected text.codes aren't working.how can i fix this?

<!doctype html><html><head><meta charset="utf-8"><title>Untitled Document</title><style>#its{	border:1px solid black;}</style></head><body><div id="its" contenteditable="true" ><p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p></div><input type="button" value="select and change" onClick="addLink();"><script>function addLink(){var links=prompt("add link","http://");document.execCommand('creatLink',false,links);}</script></body></html>
Link to comment
Share on other sites

you misspelled 'createLink'.

 

you also need to make sure designMode is turned on. and while its on, events won't work in the current document, so you'll have to resort to using iframes.

 

Or turn designMode on (inside the event call) to make the change and then turn it back off afterwards.

Edited by Hadien
Link to comment
Share on other sites

thanks!spell correction works but it is not allowing me to click on the link and visit the desired page.rather "open in a new tab" using mouse's right button works.i want to make it a clickable link.

 

iframe tag is used to creat browser window inside the main page(as far as i know).so why should i need an iframe tag here?

 

// what i am trying to do is select a word or group of word and replae it with a link :facepalm:

Edited by alzami
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...