简体   繁体   English

在Trac Wiki页面中包含JavaScript

[英]Including JavaScript in a Trac Wiki page

I want to include a JS snippet in a Wiki page. 我想在Wiki页面中包含一个JS代码段。

I read this post: 我读了这篇文章:
Referencing javascript from trac wiki 从Trac Wiki引用JavaScript
and set rendering_unsafe_content = true under [wiki] and restarted the server. 并在[wiki]下设置rendering_unsafe_content = true,然后重新启动服务器。
I then placed this in a new/empty wiki page: 然后,我将其放置在新的/空的Wiki页面中:

{{{
#!html
<script type="text/javascript" >
   alert("Test1");
</script>
}}}

but, no alert when the page loads. 但是,在页面加载时没有警报。
I've also tried this: 我也尝试过这个:

{{{
#!html
<script type="text/javascript">
$(document).ready(function() {
   alert("Test2");
});
</script>
}}}

but that also doesn't work. 但这也不起作用。

In both instances, the JS isn't even included in the rendered page (as determined by inspecting the content). 在这两种情况下,JS甚至都不包含在呈现的页面中(通过检查内容确定)。

This would seem to be pretty straightforward, so I'm puzzled that its not working... can anyone tell me what I'm missing? 这似乎很简单,所以我为它不起作用感到困惑……有人可以告诉我我所缺少的吗?

Thanks! 谢谢!
-Dave 戴夫

@RjOlios answered it: I had a typo in the trac.ini. @RjOlios回答:我在trac.ini中有一个错字。 Should be "render_unsafe_content" not "rendering_unsafe_content", and correcting that typo makes JS work. 应该是“ render_unsafe_content”而不是“ rendering_unsafe_content”,并且更正错别字使JS正常工作。 Many thanks! 非常感谢!

Also note that Trac seems to require a blank line before the line and an additional blank line after the line. 另请注意,Trac似乎需要在该行之前留空行,并在该行之后附加留空行。 Without these blank lines I find that the JS is not executed but rather rendered as text on the page. 如果没有这些空白行,我会发现JS没有执行,而是在页面上显示为文本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM