document.execCommand("CreateLink"

Hi, I am trying to create an add link button to a wysiwyg editor, anyways… What i have is a new window pops up asking for user input, the variables are then passed back from the window, then I need to make a link using the varialbes theUrl, TheTarget, and maybe theTitle.

url = theUrl + "\\" " + "target=" + "\\"" + theTarget;
theIframe.contentWindow.document.execCommand("CreateLink", false, url);

This gives me a link with the hex codes for " and space.

<a href="http://exampe.com%22%20target=%22_blank">asdf</a>

I also tried using this but I cannot get theSelection to be the text that is selected.

theSelection = theIframe.contentWindow.getSelection();
theRange = theSelection.getRangeAt(0);
theRange.collapse(false);
var newLink = theIframe.contentWindow.document.createElement("a");
var someText = document.createTextNode(theSelection);
newLink.target = theTarget;
newLink.href = theUrl;
newLink.title = theTitle;
newLink.appendChild(someText);
theRange.insertNode(newLink);

Thanks for any advice.

try using the unescape function of javascript


[left]url = theUrl + "\\" " + "target=" + "\\"" + theTarget;[/left]
[left]url = unescape(url)
theIframe.contentWindow.document.execCommand("CreateLink", false, url);[/left]

Try using extractContents() instead of collapse().

Thank you, extractContents() is exactly what i was looking for, worked perfectly.

i used the above code
but iam not getting exact answer
o/p-- (if i use \“) – <a href = 'www.yahoo.com” target = “_blank’>
(if i use \‘) – <a href = "www.yahoo.com’ target = '_blank”>
i want to add target attribute to anchor tag for above example
try to solve my problem