+ Reply to Thread
Results 1 to 3 of 3

Thread: JavaScript 'this' keyword

  1. #1
    nightbandit is offline x10Hosting Member nightbandit is an unknown quantity at this point
    Join Date
    Mar 2009
    Posts
    53

    JavaScript 'this' keyword

    I'm trying to link images with JavaScript. This is what I'm currently doing:

    HTML Code:
    <img src="filepath" alt="alt txt" onClick="window.open(this.src);" />
    But I want to have a function to make it easier on myself. Here's what I've tried:

    Code:
                        [IN HEAD SECTION]
    
                        function openImg(obj)
                        {
                                window.open(obj.src);
                        }
    
                        [IN IMG TAG]
    
                        onClick="openImg(this)"
    But it's not working. I'm new to JavaScript so could someone please explain the problem to me, and maybe tell me how to fix it?

    If you want to view the site here it is: http://craptastic.co.cc
    Last edited by nightbandit; 04-23-2009 at 10:03 PM.

  2. #2
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: JavaScript 'this' keyword

    The JS you posted looks fine. Check the error console and post relevant error messages here. What browser(s) are you having problems with? Always state the software environment.

  3. #3
    nightbandit is offline x10Hosting Member nightbandit is an unknown quantity at this point
    Join Date
    Mar 2009
    Posts
    53

    Re: JavaScript 'this' keyword

    I'm using firefox. And the error I'm getting is openImg not defined.

    Nevermind I had a typo in my script element, thanks anyays.
    Last edited by nightbandit; 04-24-2009 at 09:02 PM.

+ Reply to Thread

Similar Threads

  1. Making a site JavaScript dependent - pros/cons?
    By Tarzan in forum Programming Help
    Replies: 8
    Last Post: 07-11-2008, 10:08 AM
  2. drop down menus with JavaScript disabled?
    By sifaka in forum Free Hosting
    Replies: 1
    Last Post: 05-15-2008, 10:46 AM
  3. javascript and external javascript files problem
    By delon in forum Programming Help
    Replies: 6
    Last Post: 04-27-2008, 12:41 AM
  4. XML and Javascript
    By cuteboytm in forum Graphics & Webdesign
    Replies: 1
    Last Post: 09-21-2007, 10:00 AM
  5. Some nice-simple JavaScript effects !!
    By careerbridge in forum Scripts & 3rd Party Apps
    Replies: 1
    Last Post: 07-13-2006, 08:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers