permission denied when trying to highlight from XHR call

11 views
Skip to first unread message

Sanjiv Jivan

unread,
Jul 29, 2007, 1:38:17 AM7/29/07
to syntaxhighlighter
I'm trying to highlight html content of a page which I load using
Ajax. I have the call

dp.SyntaxHighlighter.HighlightAll('code')

at the bottom of the page. However when trying to execute this piece
of code I get a "permission denied" error. I tried replacing it with
alert('foo') and that ran fine.

Anyone tried using dp.SyntaxHighlighter to highlight content received
from Ajax?

Thanks,
Sanjiv

Sanjiv Jivan

unread,
Jul 29, 2007, 9:17:27 AM7/29/07
to syntaxhighlighter
I found the cause for this. syntaxhighlighter has this piece of code

if(highlighter.Style)
document.write('<style>' + highlighter.Style + '</style>');

which is present for the Java Brush. The problem is that my app is
running in an iframe and the document.write tries to write to the main
document when instead it should be writing to its iframe :

document.frames['frame_id'].document.write('<style>' +
highlighter.Style + '</style>');

I'm not sure that there's a way a script can find out if its running
in an frame / iframe let alone getting its frame name. So it would be
nice to disable this option and allow the user to explicitly declare
the relevant CSS in their page. In my case it would be :

.dp-j .annotation { color: #646464; }
.dp-j .number { color: #C00000; }

The other option would be to allow the user to specify the frame name
as an optional argument to dp.SyntaxHighlighter.HighlightAll. Passing
the fame name might not be possible for users in certain cases but
useful in others.

In my case I an using Google Web Toolkit (GWT) to develop my app and
GWT always runs user code in a separate iframe so this make
syntaxhighlighter unusable with GWT presently. In the case of GWT
though, the name of the iframe is known ahead of time since its a
constant that maps to the module name you chose for your application.

Sanjiv

Reply all
Reply to author
Forward
0 new messages