SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    188
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    popup when image is moused over, using onClick?

    Hello,

    I am trying to link an image to a web site using a function. The function is necessary because the image is manipulated when moused over so I lose the ability to include a simple anchor tag or onclick attribute within the image tag.

    The code below almost works, except it automatically tries to open the link when I mouseover the image. What do I need to do to make the onClick event handler work so that it does not try to open the new window when moused over?

    Code:
    function PostPopProcessing(obj)
    { 	
    document.getElementById("cof").onClick=window.open('http://www.url.org');
    }
    Thank you for your insight.

  2. #2
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try:

    Code:
    document.getElementById("cof").onClick= function () {
      window.open('http://www.url.org');
    };
    instead. What's happening is that your event handler is evaluating the window.open function to assign it to onClick instead of using it. That's why you want the anonymous function inline there.

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    188
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the idea. It does not seem to work. The odd thing is that no javascript error is thrown. When I click, nothing happens. If I use an id that I know is incorrect it throws an error, so it is definitely registering the use of onClick, just no new window.

    Thank you.
    Code:
    function PostPopProcessing(obj)
    { 	document.getElementById("popcopycof").onClick = function() {
    	window.open('http://www.url.org');
    };
    }

  4. #4
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    onClick works in HTML's inline event handlers because HTML is case-insensitive (though not in XHTML because it's case-sensitive), but Javascript isn't and onClick doesn't exist in Javascript. It's onclick, all lowercase.

  5. #5
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    188
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    *hangs head sheepishly*

    Thank you Raffles. It works like a charm now.

    Thanks again for everyone's help.


Bookmarks

Posting Permissions

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