jump to content

Satheesh Babu

Shows how to grab and set the target property for a link using custom dialog.

Note - if you don't understand what I'm talking about, please see the previous article.


Several people had asked me how to modify the dialog for inserting links so that they can set a "target" property too. Normally, you would expect that 'selection.createRange().target' will give you this. Though the documentation on MSDN says this is correct, it does not work.


Only way I could find was to make a regular expression parse on the range to get the target and href out manually.


An example is shown below.

   var aLINK = oRange.htmlText.match(/<a.*href=['"]*([^"' ]+)['"]*/i);
   var aTARGET = oRange.htmlText.match(/<a.*target=['"]*([^"' ]+)['"]*/i);
   args["LinkUrl"] = aLINK[1];
   args["LinkTarget"] = (aTARGET != null?aTARGET[1]:null);

Code listing for full function.