Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Syntaxhighlighting lost when AJAX call is made

I have a page on my website that I am making a call to using a jQuery ajax call. It loads in a div. But whenever I the page is loaded, it loses the snytax highlighting that it should be displaying. Ex:

<html>
<head>
<!-- syntax highlighting script -->
<script type="text/javascript" src="syntaxhighlighter.js"></script>
</head>
<body>
<!-- div that displays ajax page cal -->
<div id="awesomeo">

</div>
</body>
</html>

It works on the initial page load if I have something in awesomeo but if a page is loaded via AJAX into the div, the syntax disappears.

EDIT: The following is the code that is in the header:

<script type="text/javascript" src="/scripts/shCore.js"></script>
<script type="text/javascript" src="/scripts/shBrushBash.js"></script>
<script type="text/javascript" src="/scripts/shBrushCpp.js"></script>
<script type="text/javascript" src="/scripts/shBrushCSharp.js"></script>
<script type="text/javascript" src="/scripts/shBrushCss.js"></script>
<script type="text/javascript" src="/scripts/shBrushJava.js"></script>
<script type="text/javascript" src="/scripts/shBrushJScript.js"></script>
<script type="text/javascript" src="/scripts/shBrushPhp.js"></script>
<script type="text/javascript" src="/scripts/shBrushPlain.js"></script>

<link type="text/css" rel="stylesheet" href="/styles/shCore.css"/>
<link type="text/css" rel="stylesheet" href="/styles/shThemeDefault.css"/>

<script type="text/javascript">
    SyntaxHighlighter.config.clipboardSwf = '/scripts/clipboard.swf';
    SyntaxHighlighter.all();
</script>

This is from: http://alexgorbatchev.com/wiki/SyntaxHighlighter That is all that is used for syntax highlighting... Suggestions?

like image 901
kylex Avatar asked Feb 20 '10 06:02

kylex


2 Answers

Figured it out: Adding

<script type="text/javascript">
    SyntaxHighlighter.highlight();
</script>

on the page being called works.

like image 78
kylex Avatar answered Nov 11 '22 13:11

kylex


your syntaxhighlighter probably has a function bound to document.onload. You'll need to find that function and call it again.

like image 1
Jimmy Avatar answered Nov 11 '22 14:11

Jimmy