javascript TinyMCE 字段中的脚本标记未正确保存
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24614301/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Script tags in TinyMCE fields are not saving correctly
提问by WayneP
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.
我在我的网站上运行 tinyMCE,我正在尝试插入脚本标签。我正在尝试将我的脚本标签插入到 tinyMCE 实例源的正文中。
However, when I do I get problems. When I submit the form including the tinyMCE element It strips the tags.
但是,当我这样做时,我会遇到问题。当我提交包含 tinyMCE 元素的表单时,它会去除标签。
I have tried the following lines below with still no success.
我已经尝试了以下几行,但仍然没有成功。
allow_script_urls: true
valid_elements : '*[*]'
extended_valid_elements: 'script[language|type]'
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.
我注意到的一件事是,如果我必须将脚本代码发布到 tinymce 实例的源代码部分并且它可以工作。但是,我需要能够将它添加到<body>
tinymce 实例的 ,以便我可以看到它的预览等。
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
谢谢
回答by dmullings
Try the following:
请尝试以下操作:
extended_valid_elements: 'script[language|type|src]'
extended_valid_elements: 'script[language|type|src]'
I see that you've already tried updating the extended_valid_elements
property using
我看到您已经尝试extended_valid_elements
使用更新属性
'script[language|type]'
but you forgot to allow the src attribute for the script tags
'script[language|type]'
但是您忘记允许脚本标签的 src 属性
so right now the src
attribute is being stripped out.
所以现在这个src
属性正在被剥离。
回答by anoldermark
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
似乎存在一个错误,如果脚本标记包含在 div TinyMce 中,则会转储脚本。(即使您正确使用了extended_valid_elements)TinyMCE 使用起来也很烦人
回答by Alex Celmer
What I did to solve the problem was putting the script block inside a tag <code>
tag.
我为解决这个问题所做的是将脚本块放在标签<code>
标记中。
<code>
<script>alert("abc");</script>
</code>