Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    How can I make addEventListener, and attachEvent helper function?

    Hi guys, I'm learning how to make a helper function for the attachEvent and addEventListener methods which will take 3 or 2 arguments. I'm a newbie, so im trying to practice this kind of programming to advance my learning...

    Code:
    $e('click', fnction, false);
    Is this possible? I want to make my own function which will take 2 or 3 arguments, and test whether addEventListener or the attachEvent is available in the browser.

    Code:
    var $e = function(evnt, fnc, prpgtion) { //i want prpgtion to become optional.
    Then I also want to test whether the method is available in the browser, then it will decide which will be used: the addEventListener or attachEvent

    I dont know how to make one, please teach me and explain to me how to code this kind of helper function...

    Code:
    var $e = function(evnt, fnction, prpgt) {
    	var use;
    	if (typeof this.addEventListener != 'undefined')
    	{
    		use = this.addEventListener(evnt, fnction, prpgt);
    	} else if(typeof this.attachEvent != 'undefined')
    	{
    		evnt += "on";
    		use = this.attachEvent(evnt, fnction);
    	}
    	return use;
    }
    This is the one that will check the browser, I dont even know if it is correct

    Thanks
    Last edited by alcatraz678; 09-14-2008 at 01:43 PM.

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • Users who have thanked shyam for this post:

    alcatraz678 (09-15-2008)

  • #3
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts
    thanks shyam, the link was very helpful


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •