1

I have a problem running javascripts from trac. I know there are security issues around this, but my trac installation is only used as an intranet.

I have got the following code to work (requires setting rendering_unsafe_content = true under [wiki] in trac.ini):

{{{
#!html

<script type="text/javascript" >
document.write("This is a test")

</script>

}}}

However, replacing this with the javascript in a seperate file will fail:

{{{
#!html

<script type="text/javascript" src="/tracproject/htdocs/test.js" >

</script>


}}}

where tracproject is the root folder of trac and test.js contains document.write("This is a test").

Any clues?

Bjørkman
  • 11
  • 2
  • Are you 100% sure `/tracproject/htdocs/test.js` exists? Can you verify e.g. using Firebug whether the script file actually gets loaded? What does the final generated HTML look like? – Pekka Jan 02 '11 at 22:26
  • I think you are on the right track, Pekka. I tried Firebug and when I inspected the code after the – Bjørkman Jan 03 '11 at 13:50
  • The line 9 Error: Not found - Modem Tech probably means that the script never was loaded? I haven't used this debugger before so I'm not too familiar with its features. Does this observation give any new clues? – Bjørkman Jan 03 '11 at 13:56

2 Answers2

0

The option is [wiki] render_unsafe_content (see documentation). You can reference the file in your site htdocs directory on the path /tracproject/chrome/site/test.js. I tried your example just now and it work correctly once the src path is changed.

See the TracInterfaceCustomization page for more details.

RjOllos
  • 2,900
  • 1
  • 19
  • 29
0

Have you tried the 'Add Headers Plugin' (http://trac-hacks.org/wiki/AddHeadersPlugin) ? It looks like it allows you to do include custom javascript like you want but in a more straightforward way than having to modify templates directly.

bta
  • 43,959
  • 6
  • 69
  • 99