php - syntax highlighter doesn't work after call back -
So I'm new to JS & amp; Php and I am trying to print a piece of code from a call back function
& Lt; H2 & gt; ..... & lt; / H2 & gt; & Lt; Button onclick = "loadXMLDoc ();" & Gt; Get data & lt; / Button & gt; & Lt; Div id = "mydiv" & gt; & Lt; H2 & gt; ... & lt; / H2 & gt; & Lt; / Div & gt; & Lt; / Body & gt; & Lt; / Html & gt; and like my php file
& lt; Php $ ch = curl_init (); $ Url = 'someurl'; $ Timeout = 5; Curl_setopt ($ ch, CURLOPT_URL, $ url); Curl_setopt ($ CH, CURLOPT_RETURNTRANSFER, 1); Curl_setopt ($ CH, CURLOPT_CONNECTTIMEOUT, $ timeout); $ Data = curl_xac ($ ch); Curl_close ($ ch); Echo "& lt; script type = 'text / javascript' src = 'SyntaxHighlighter / scripts / shCore.js' & gt; & lt; / script & gt; & lt; script type =' text / javascript 'src =' SyntaxHighlighter / Scripts / shBrushJava.js' & gt; & lt; / script & gt; link href = 'SyntaxHighlighter / styles / shCore.css' rel =' stylesheet 'type =' text / css' / & gt; Lt; link href = 'SyntaxHighlighter / styles / shThemeDefault.css' Rel = 'stylesheet' type = 'text / css' / & gt; "; Echo "& lt; east class = 'brush: java;' & Gt; "; $ Data echo; Echo "& lt; / pre & gt;"; Echo '& lt; Script type = "text / javascript" & gt; Syntax Highlighter Highlight (); & Lt; / Script & gt; '; ? & Gt; And it seems to me the syntax highlighter works on the php file, but do not call back after ... I did some research and I know that I have SyntaxHighlighter.highlight ( I'm considered to use) instead of all () code, but I've already done this. There is a problem with my code structure
& lt ;? Script & gt; The tag is not executed by the browser added by the internal HTML. You need to implement them themselves. Caps on = document.getElementById ("myDiv") getElementsByTagName ("script"); If (script & script length) {for (var i = 0; i & lt; scripts.length; i ++) {eval (script [i] .winnerHTML); }} Alternatively you can add script nodes to the page instead of removing it:
// ... for (var I = 0; i & lt; scripts.length; i ++) {var s = document.createElement ('script'); S.innerHTML = eval (script [i] .winnerHTML); Document.body.appendChild (s); } But it is similar to extracting the code anyway (in fact, it does not seem difficult about that code is unchecked in both ways).
A better way is to add syntax highlighting files at the top of the page to avoid script injection completely and after code SyntaxHighlighter.highlight () , you delete the code from the inside. goes.
Comments
Post a Comment