weird attempted escaping behaviour for javascript in post
-
Hi. Usually I have no problem posting javascript in my posts (actual javascript code that will run when displayed on a client as opposed to just displaying source code). But now I am having some difficulty getting the following to work in a post:
<script type="text/javascript"> function displayContent(json) { var entries = json.feed.entry || []; var closingPrices = []; var j = 0; for(i=41;i<=51;i++){ closingPrices[j] = entries[i].content.$t.split(",")[0].split(":")[1].split(" ")[1]; j++; } var image = "http://chart.apis.google.com/chart?chs=250x100&cht=lc&chxt=x,y,r"+ "&chxt=x,y,y&chxl=0:|Nov%2028|Dec%205|12|1:|81|83|85|87|89|2:|in%2000s&chds=81,89"; var chd = "&chd=t:" for(i=0;i<closingPrices.length;i++){ if(i>0) chd = chd + ","; chd = chd + (""+(closingPrices[i]/100)); } image = image + chd; document.getElementById("chart").src = image; } </script>For some reason, wordpress encodes some of the double quotes before uploading (“) but not others. Thus when I view the page the javascript fails with syntax errors on these wrongly encoded double quotes.
The quotes that are changed to “ in the above code are emboldened as follows:
if(i>0) chd = chd + “,“;
chd = chd + (““+(closingPrices[i]/100));
…
document.getElementById(“chart“).src = image;Why would WordPress encode some but not all and how can I prevent it from doing so?
The topic ‘weird attempted escaping behaviour for javascript in post’ is closed to new replies.