Can I use JavaScript in my Blog entries?

Jun 8, 2010 at 6:29 PM

I tried a little piece of JavaScript in a Blog entry today and it didn't seem to work. Is it correct that it isn't possible to use JavaScript in your entries? Would it be a security issue to do this?

Thank you in advance!

Jun 12, 2010 at 3:05 PM

javascript works fine, just make sure you are in HTML editing mode when inserting it.

Jun 16, 2010 at 11:23 AM
Thank you very much. Probably the script I tried was not working well. Any change that PHP can be used (When installed on Server of course)?
Jun 16, 2010 at 11:37 AM

No php unless you have the script running elsewhere and put its contents in an iframe.

Jun 16, 2010 at 11:39 AM
Ok, I understand. Thank you for the quick answer!
Jun 16, 2010 at 11:42 AM

Maybe you copuld post the error and the script. Someone here may be able to help. Some scripts do conflict with BE's jquery implementation but are usually pretty easy to fix.

Jun 16, 2010 at 11:49 AM
First let me tell you what my needs are. On my blog I link to new radio control aircraft/boat/cars products that come out. Most of these products come from a site that provides an, what they call, 'Api' to retrieve stock status, price, description and shipping weight. I am interested to use the stock-status of the products I write blog posts about. This is the line that can be used to retrieve the stock status of an item: There is also a piece of code available to dropshippers about order status information (Boolean Posted and Text trackingno). That code is JavaScript, see below: <script> //change the switch and id in the http string to view different product details var xmlhttp=false; xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");"GET", "",true); xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4) { //alert(xmlhttp.responseText); document.getElementById('testarea').innerHTML=xmlhttp.responseText; } } xmlhttp.send(null) </script> This code didn't work when I tested in a Blog post and also when I tried to use the stock status line in that code it didn't work. Most important for now is to get the stock status working in my Blog post. If you have ideas for this, I would love to hear them. Thank you in advance!
Jun 16, 2010 at 11:50 AM
It seems that the forums mess up my post. I hope you can make something of it....
Jun 16, 2010 at 12:16 PM

The script itself works fine in a post except for it throws security warnings.

Got to the post and check use raw HTML editor. Put your ID for the info, in this case "testarea", before the script so the ID can be found.

We have <span id="testarea"></span> on hand.
<script>        //change the switch and id in the http string to view different product details 
        var xmlhttp = false;
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");"GET", "", true);
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4) {
                document.getElementById('testarea').innerHTML = xmlhttp.responseText;
        xmlhttp.send(null) </script>
Jun 16, 2010 at 12:48 PM

I need to clarify my "works fine" statement. 

It works fine in Internet Explorer with ActiveX warnings. It doesn't work in any browser that doesn't support ActiveX which I believe is all the rest without plugins. 

I recommend you (or someone else) rewrite the script to be cross browser compatible. Unfortunately that is something I am unable to help you with.

Jun 16, 2010 at 10:36 PM

Hi Taylex,

Thanks for your code and your comment that it only works for Internet Explorer.

I inserted your code into the raw-html editor and clicked the 'update' button. Then I opened (without saving the blog-post) the raw-html again to find out that the span-tag was gone. After changing the span-tags a little bit the changes weren't removed anymore. I made this change from: <span id="testarea"></span> to:

<span id="testarea">&nbsp</span>

I also changed the line with 'xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");' to

xmlhttp = new XMLHttpRequest();

Unfortunately, I don't get a value back, so there is still something to investigate. I know that the final code will have to check for the browser is used at the client. Just need to get a value back first...

Thanks for your help so far!

Jun 16, 2010 at 10:50 PM

I don't get an error with the changes I mentioned above in Firefox, but also not a valid return value. When I checked your code in IE, I get a 'permission denied' error. This probably has to do with calling an url that is not on my domain. Let's see what I can do about that.