I have some javascript in a div to make it move from an iframe to the main page. It works fine but when I use & like this:
function JS_onMouseOverBG(e, i_bg) {
if( (block == 0)&&(i_bg != selected) ) {
e.style.cursor = 'pointer' ;
} else {
e.style.cursor = '' ;
}
}
Then & becomes & and I have this firefox error:
Erreur : missing ) after condition
Fichier Source : http://192.168.0.20/lb/?p=467&w=prefs_bggen
Ligne : 905, Colonne : 22
Code Source :
if( (block == 0)&&(i_bg != selected) ) {
I tried using the unicode \u0026 of & but it does not work. I have an error of illegal character.
How can I do to use & in such a case ?
Edit:
I’ve found the solution, if someone looks for the same issue:
function JS_decode(str) {
var div = document.createElement('div');
div.innerHTML = str ;
var decoded = div.firstChild.nodeValue;
return decoded ;
}
And I use this function for this DIV DIV_cover_js containing the Javascript code:
var eleJS = document.createElement("script") ;
eleJS.type = 'text/javascript' ;
eleJS.text = get('DIV_cover_js').innerHTML ;
eleJS.text = JS_decode(WP.eleJS.text) ;
eval(eleJS.text);
(Quoted from a comment by the OP):
If the original HTML includes
&&then that is an error and the browser is correcting it.You then get a serialisation of the DOM to HTML and try to treat some HTML as JavaScript.
If you really want to do this, then you should extract a
textNodeand use itsdatainstead ofinnerHTML, however the approach is ugly, slow and hard to debug. You should have a proper JS function loaded via a<script>element in the first place.