Is it possible to add javascript in rte? If yes, then how? | Community
Skip to main content
Nupur_Jain
Nupur_JainAccepted solution
Employee
Mar 15, 2017 5:03 AM UTC

Hey,

In classic UI ,you can use Xtype htmleditor instead of rte if you want to write js. It won't remove the script tag. But for touch UI , I don't see any resourceType for that.

Hope it helps!

Thanks

Nupur

11 replies

joerghoh
Employee
Oct 18, 2018 11:33 AM UTC

Don't let an author enter Javascript as part of the page. You are opening the box of pandora then, and authors start embedding stuff you never dreamed of. Not to mention security issues.

Please, don't.

Translate
prabodh
Level 2
Oct 18, 2018 10:44 AM UTC

I have removed the script tag from whitespaceprocessor.js but to no avail, script tag is still getting stripped off.

Could you please let me know what changes you have made in whitespaceprocessor.js ?

Translate
Himanshu_Singhal
New Participant
Apr 5, 2017 9:39 AM UTC

vinayk70574604 wrote...

Hi Himanshu,

Could you explain a little more about the requirement which requires author to place a code(<script>), because this doesn't look like a good practice? If the content has to be beautified or modified for some reasons, it can always be done in the component's script (sightly or JSP). Further if you still have such a requirement to do, you may try:

WhitespaceProcessor.js is restricting few tags by default, you might update this to ignore the tags you want.

You could refer this post for more help:

http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manager.topic.html/forum__dqe0-after_updatefromcq.html

 

Thanks Vinayak,

I've made changes in WhitespaceProcessor.js for foundation/components/text and it's now taking <script> tag if wrapped b/w <div> tags.

Translate
Himanshu_Singhal
New Participant
Apr 5, 2017 9:28 AM UTC

nupurjain wrote...

Hey,

In classic UI ,you can use Xtype htmleditor instead of rte if you want to write js. It won't remove the script tag. But for touch UI , I don't see any resourceType for that.

Hope it helps!

Thanks

Nupur

 

Thanks Nupur!
But, the requirements was for Touch UI. For foundation/components/text, we can override WhiteSpaceProcessor.js to allow tags. Then, <script> tag can be used in RTE by keeping it wrapped under <div> tags.

Translate
Nupur_Jain
Nupur_JainAccepted solution
Employee
Mar 15, 2017 5:03 AM UTC

Hey,

In classic UI ,you can use Xtype htmleditor instead of rte if you want to write js. It won't remove the script tag. But for touch UI , I don't see any resourceType for that.

Hope it helps!

Thanks

Nupur

Translate
Level 2
Sep 3, 2022 9:28 PM UTC

How can we remove .html extension from the rte at content fragment level?

Translate
Level 2
Mar 14, 2017 11:51 AM UTC

Hi Himanshu,

Could you explain a little more about the requirement which requires author to place a code(<script>), because this doesn't look like a good practice? If the content has to be beautified or modified for some reasons, it can always be done in the component's script (sightly or JSP). Further if you still have such a requirement to do, you may try:

WhitespaceProcessor.js is restricting few tags by default, you might update this to ignore the tags you want.

You could refer this post for more help:

http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manager.topic.html/forum__dqe0-after_updatefromcq.html

Translate
kautuk_sahni
Employee
Mar 14, 2017 9:15 AM UTC

There is one more article where custom color picker is implemented:

Link:- http://experience-aem.blogspot.in/2016/04/aem-62-touch-ui-dialog-rte-rich-text-editor-color-picker-plugin.html

Link:- http://experience-aem.blogspot.in/2016/04/aem-62-touchui-dialog-rte-mini-rte-upper-case-plugin.html

//Please try it and let us know, what is the problem that you are facing. Please have a look at the articles here you can see that, we have created a clientlibs folder with categories =  rte.coralui2

  now create a JS file and add plugin code in it. 

~kautuk

Translate
Kautuk Sahni
smacdonald2008
Level 10
Mar 13, 2017 3:58 PM UTC

Look at Sreekanth's blog here. He has some blogs entries that use RTE and code: 

http://experience-aem.blogspot.ca/2013/08/in-blog-experiencing-adobe-experience.html

Translate
Himanshu_Singhal
New Participant
Mar 13, 2017 3:49 PM UTC

Rte is removing <script> tag.

Translate
daniel_henriqu1
Level 4
Mar 13, 2017 1:49 PM UTC

Hi, Himanshu.

I haven't tried that before...

Is the RTE removing the <script> content or are you having a hard time trying to render it?
Are you able to see the <script> tag in the corresponding node under your page (CRX DE)?

Regards,

Daniel.

Translate