Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set target attribute in tinyMCE

Tags:

tinymce

I have set a link to some text using tinymce.execCommand("CreateLink", False, theLink). The problem is that I want to set "Target=_blank".

How do I set a Target attribute after the above?

Thanks.

like image 232
Sandeep Kumar Avatar asked Dec 04 '22 09:12

Sandeep Kumar


2 Answers

Are you trying to set the target attribute to _blank on all user-provided links in TinyMCE? If so, set this property in your tinymce.init configuration:

extended_valid_elements: 'a[href|target=_blank]'

This works for me on TinyMCE 4.0.2.

With this configuration, all links in the editor will have target set to _blank when the editor saves. (Additionally, all attributes other than href and target will be removed since I excluded them in the configuration; add whatever valid attributes/constraints that you wish to allow.)

see: http://www.tinymce.com/wiki.php/configuration:extended_valid_elements

If these are user-provided links, then you may also want to set rel=nofollow for all links they provide.

like image 69
Ryan Avatar answered Mar 08 '23 05:03

Ryan


Making 'New page' an only option did work for me (see: http://www.tinymce.com/wiki.php/Configuration:target_list) in version 4.1.0

target_list: [ {title: 'New page', value: '_blank', selected: true} ]
like image 41
elshnkhll Avatar answered Mar 08 '23 05:03

elshnkhll