11 Jun 2007, 4:57am
Projects:
by Cliffano Subagio

leave a comment
  • SCode Image Reload

    Sometimes the numbers on SCodePlugin-generated CAPTCHA image are not easy to read. And rather than refreshing the whole page, it would be nice to reload only the image and generate a new / more readable code.

    In order to give this a go, I modified the comment form on Melbourne photoblog and added a short Javascript code to refresh the image source. You can try it yourself on this form, just click the text “Generate another code” and wait shortly for the image to be reloaded with a new code.

    I have updated the Usage sample code on SCode Plugin wiki page with this improvement.

    As a side note, I found a problem where modifying img.src value via anchor tag’s onclick attribute does not work on IE 6 and the image will just disappear, while it works just fine on Firefox 2 and Opera 8.5 .

    function reloadSCode() {
      var scodeImage = document.getElementById("scodeImage");
      scodeImage.src="$BLOJSOM_BLOG.getBlogBaseURL()/captcha?flavor=kink&t=" + (new Date()).getMilliseconds();
    }
    <a href="javascript: void(0);" onclick="reloadSCode();">Generate another code</a>.

    After some mucking around, I found out that the function call must be made from the href attribute. This works on the browsers mentioned above.

    <a href="javascript: reloadSCode();">Generate another code</a>.

    Them browsers better implement proper Javascript standard before doomsday comes.

    18 Apr 2006, 11:00pm
    Projects:
    by Cliffano Subagio

    1 comment
  • Trailing Comma Within JSON’s Array

    I was debugging an AJAXy app which uses JSON as the data format, and it was fine with Firefox but not with Internet Explorer. After further debugging, the culprit turned out to be trailing commas within the data.

    {"foo": {
        "bar": [
            {"id": "1", "url": "http://www.hostA.com"},
            {"id": "2", "url": "http://www.hostB.com"},
    ] }}

    theObject.foo.bar.length returns 2 in Firefox, but it returns 3 in Internet Explorer. The solution was obviously to remove the last comma.

    I’m guessing the problem is more to Javascript array.length which is handled differently between browsers.

    Update: HTML comments embedded within what’s supposed to be JSON’s data will be ignored by Firefox, while they will cause failure during eval in Internet Explorer.

     
      
     

    Recent Posts

    Recent Comments

    • Nare: Once I started reading the book, I didn’t want to let go. It was both...
    • Cliffano Subagio: I’ve raised issue 2624 to capture this request. Thanks.
    • stlecho: Is it possible to execute the “Build Now” functionality with...
    • Cliffano Subagio: @Eric Thanks a lot for the translation. I’ve added fr-FR locale...
    • Moses Karani Mutonga: I saw Dr. Randy giving the lecture and I was moved to tears. God...

    Linkroll