Feb 242010
 

Tested in IE 8 and Firefox 3.6, this JavaScript will simulate a user clicking on a link.

<script language="JavaScript">
// Execute the called event
function fireEvent(obj,evt) {
    var fireOnThis = obj;
    if ( document.createEvent ) {
        var evObj = document.createEvent('MouseEvents');
        evObj.initEvent( evt, true, false );
        fireOnThis.dispatchEvent(evObj);
    } else if ( document.createEventObject ) {
        fireOnThis.fireEvent('on'+evt);
    }
}

</script>

Call it using

fireEvent(document.getElementById(‘idOfLink’), ‘click’);

where “idOfLink” is the name/ID of the link to be clicked. You can highlight from “Example” below down to the “Clear” link and click view source to see the code in action.

Example


    


Link one
Link two
Clear