Script tags in TinyMCE fields are not saving correctly

21,461

Solution 1

Try the following:

extended_valid_elements: 'script[language|type|src]'

I see that you've already tried updating the extended_valid_elements property using

'script[language|type]' but you forgot to allow the src attribute for the script tags

so right now the src attribute is being stripped out.

Solution 2

There seems to be a bug where if a script tag is wrapped in a div TinyMce dumps the script. (even if you have extended_valid_elements correctly) TinyMCE can be very annoying to use

Solution 3

What I did to solve the problem was putting the script block inside a tag <code> tag.

<code>
     <script>alert("abc");</script>
</code>
Share:
21,461
WayneP
Author by

WayneP

Updated on October 29, 2020

Comments

  • WayneP
    WayneP over 3 years

    I am running tinyMCE on my site and I'm trying to insert script tags. I am trying to insert my script tags into the body of the source of the tinyMCE instance.

    However, when I do I get problems. When I submit the form including the tinyMCE element It strips the tags.

    I have tried the following lines below with still no success.

    • allow_script_urls: true
    • valid_elements : '*[*]'
    • extended_valid_elements: 'script[language|type]'

    One thing I have noticed though that if I have to post the script code to the section of the source code of the tinymce instance and it works. However, I need to be able to add it to the <body> of the tinymce instance so I can see previews etc of it.

    Below is the script tag I'm trying to upload.

    <script type="text/javascript" src="http://resources.32red.com/ad.aspx?pid=237638&bid=3344"></script>
    

    Can anyone shed any light on this?

    Thanks

  • peter jalton
    peter jalton over 7 years
    I have just verified this today. Unfortunate. But glad to see someone else acknowledged it.
  • Simon East
    Simon East over 6 years
    Grr. That's annoying. I think I'm hitting this too. I wonder if this was fixed in a particular version.
  • Simon East
    Simon East over 6 years
    I'm having the same issue, and unfortunately, even when I added script[language|type|src] it still kept stripping out the src. On TinyMCE 3.5.11. Haven't found a fix yet, except for upgrading to v4, which is a bit of effort.
  • Simon East
    Simon East over 6 years
    I kept removing TinyMCE plugins until I found the culprit - the jwplayer plugin I was using was stripping out the <script src="..."> for some reason.
  • agapitocandemor
    agapitocandemor about 5 years
    extended_valid_elements : "script[src|async|defer|type|charset]"