Archive for February, 2010

Javascript: Triggering a click event on a element

Saturday, February 27th, 2010

Sometime, the jQuery(“#xx”).click() does not work. So, here is a way to do it directly:

var e = document.createEvent('MouseEvents');
e.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
var r = $("#myElement").get(0).dispatchEvent(e);

Obviously, you can use the document.getElementById(“myElement”) if you do not want any jQuery dependency.

javascript: Get parent window location href from an iFrame

Monday, February 22nd, 2010

Assuming the iframe is from the same domain that the top window, use frameElement.ownerDocument to get to the parent document.

var topWindowHref = window.frameElement.ownerDocument.location.href

javascript: Remove items from an array

Monday, February 22nd, 2010

From John Resig Javascript array remove

Array.prototype.remove = function(from, to) {
  var rest = this.slice((to || from) + 1 || this.length);
  this.length = from < 0 ? this.length + from : from;
  return this.push.apply(this, rest);


// Remove the second item from the array
// Remove the second-to-last item from the array
// Remove the second and third items from the array
// Remove the last and second-to-last items from the array

Chrome: Cheat Sheet for Writing a Chrome Extension

Saturday, February 13th, 2010

Getting started official tutorial


  "name": "My First Extension",
  "version": "1.0",
  "description": "The first extension that I made.",
  "browser_action": {
    "default_icon": "icon.png",
    "popup": "popup.html"
  "permissions": [

See also: Browser Actions

Debug & Inspect extension

  1. chrome-extension://extensionId/popup.html to see the page
  2. got to chrome://extensions/ and click on popup.html
See also: Debug extensions

Android: Take an android screenshot from a PC

Friday, February 12th, 2010
  1. Install Android SDK and Android Driver
  2. Set android USB mode to debug (Settings > Applications > Development > USB Debugging)
  3. Connect Android to PC with USB cable
  4. launch android-sdk-windowstoolsddms.bat
  5. Click on Device > Screen Capture (or Ctrl S)
Tutorial video (not sure why the driver need to be installed manually. I installed it normally and it worked)

Java: Move a File to a new Directory (Folder)

Saturday, February 6th, 2010

Yes, File.renameTo is used to move file.

// File (or directory) to be moved
    File file = new File("filename");

    // Destination directory
    File dir = new File("directoryname");

    // Move file to new directory
    boolean success = file.renameTo(new File(dir, file.getName()));
    if (!success) {
        // File was not successfully moved


jQuery: jQuery event with RaphaelJs

Friday, February 5th, 2010


<div id="rtest">

Javascript code

<script type="text/javascript">
	var paper = Raphael("rtest", 320, 200);
	var circle =, 40, 30);
  	 "stroke": "#336699",
	  "fill": "#fbfbfb"

		var circle = this.raphael;

                //Toggle the circle fill color
                if (circle.attr("fill") == "#333333") {
		     circle.attr("fill", "#fbfbfb");
                } else {
		     circle.attr("fill", "#333333");

See RaphaelJs Event doc

HTML5: Charts libs (JQuery, Raphael, Flash, Google)

Wednesday, February 3rd, 2010

jQuery: Input Focus and Select

Monday, February 1st, 2010

This will focus and select the text of a given input. Nice to help the user doing the most likely action.

$("input[name='First Name']").focus().select();

or using the “HTML5″ autofocus

<input type="text" autofocus="autofocus" />