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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2003
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry What Can I replace with elementFromPoint for Netscape browser?

    Please help out!!!

    The following code works for IE, but not for Netscape.

    var objCell = document.elementFromPoint( window.event.x, window.event.y );
    if ( objCell.tagName != "TD" )
    return;

    I would like to know what can be used to get object in Netscape

  • #2
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    I was actually just working on an efficient emulation of that method, using various methods. My first few hunches didn't end up working, but I'm sure it still can be done with some intelligent code.

    If you don't mind brute-forcing the location, brothercake uses something similar in his chess script:
    http://www.brothercake.com/chess/

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It certainly is brute force what I've done - it basically iterates through each element and says, where is it - then compares the figures looking for a best-fit with the co-ordinates I want. Not efficient, but it works.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #4
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    I got it working. However, I am apparently using a property that was introduced in the 1.4 branch of Mozilla, which limits this to Mozilla 1.4 builds, Firebird 0.6, and anything else built recently:

    Code:
    // Program:      document.elementFromPoint(int clientX, int clientY) in Gecko
    // Author:       Jason Karl Davis (www.jasonkarldavis.com)
    // Date:         15 June 2003
    // Purpose:      Emulate Internet Explorer's document.elementFromPoint method as described here:
    //               http://msdn.microsoft.com/workshop/a...tfrompoint.asp
    // Requirements: A browser built off of the 1.4 branch of Mozilla (or better)
    // Distribution: You may freely distribute and use this script as long as these comments remain intact
    
    if (navigator.product == "Gecko") {
    	Document.prototype.elementFromPoint = function(x, y) {
    		this.addEventListener("mousemove", this.elementFromPoint__handler, false);
    		var event = this.createEvent("MouseEvents");
    		var box = this.getBoxObjectFor(this.documentElement);
    		var screenDelta = { x: box.screenX, y: box.screenY };
    		event.initMouseEvent("mousemove", true, false, this.defaultView, 0,
    		                      x + screenDelta.x, y + screenDelta.y, x, y,
    		                      false, false, false, false, 0, null);
    		this.dispatchEvent(event);
    		this.removeEventListener("mousemove", this.elementFromPoint__handler, false);
    		return this.elementFromPoint__target;
    	}
    	Document.prototype.elementFromPoint__handler = function (event) {
    		this.elementFromPoint__target = event.explicitOriginalTarget;
    	
    		// reparent target if it is a text node to emulate IE's behavior
    		if (this.elementFromPoint__target.nodeType == Node.TEXT_NODE)
    			this.elementFromPoint__target = this.elementFromPoint__target.parentNode;
    	
    		// change an HTML target to a BODY target to emulate IE's behavior (if we are in an HTML document)
    		if (this.elementFromPoint__target.nodeName.toUpperCase() == "HTML" && this.documentElement.nodeName.toUpperCase() == "HTML")
    			this.elementFromPoint__target = this.getElementsByTagName("BODY").item(0);
    
    		event.preventDefault();
    		event.stopPropagation();
    	}
    	Document.prototype.elementFromPoint__target = null;
    }


  •  

    Posting Permissions

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