I tried to use it but i guess i failed... here is a code:
<html>
<head>
<title></title>
<script type="text/javascript">
function closedWin() {
confirm("close ?");
return false; /* which will not allow to close the window */
}
if(window.addEventListener) {
window.addEventListener("close", closedWin, false);
}
I recently had need for the method document.elementFromPoint() found in Internet Explorer (http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/elementfrompoint.asp).
My immediate method for implementing this was artificially creating an arbitrary mouse event (decided on mousemove) at the specified coordinates, setting up an event listener on the document, firing the event, record the target, and remove the listener.
However, I apparently didn't pay close enough attention to this (http://www.w3.org/TR/2000/REC-DOM-Level-2-Events-20001113/events.html#Events-EventTarget-dispatchEvent):
The target of the event is the EventTarget on which dispatchEvent is called.
However, I had a hunch that Mozilla was merely redirecting the event to the document to be correct, and actually stored somewhere the "correct" target. After dumping the event object, I found a property which must have been recently introduced (Mozilla 1.4 branch apparently) called "explicitOriginalTarget" which is like originalTarget, but apparently never targets anonymous content, and in this case, also differs by referring to the element where the coordinates of the mouse event were.
Anyhoo, here's some code. I've tested it in various Mozilla 1.4 builds successfully (and double checked explicitOriginalTarget in < 1.4 builds to find that it doesn't exist). Firebird 0.6 is also based on 1.4, so it works in that too. By using the browser's box object and mouse events, instead of hacking my own, I don't think there should be any issues with it picking up elements that can't be seen.
// 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/author/dhtml/reference/methods/elementfrompoint.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);
And the reason I prototyped Document instead of adding it to document directly is that any extra documents you may have loaded on the same page inherit those methods. For example, an iframe or something. And it /should/ be usable in other, non-HTML documents as well, such as MathML, SVG, XUL, etc. :)
I'm still getting to grips with Javascript parsing through http://www.w3schools.com/xml/xml_parser.asp. The problem is that I need a Gecko equivalent to the Internet Explorer example at the bottom of the page.
I need to parse XML that is in a variable from a Prototype ajax request.
People have complained that window.find() doesn't work, and everyone knows Gecko doesn't support IE's proprietary TextRange object, some have assumed you can't do this in Gecko.
I have a HTML and I am opening another link in a separate window using window.open() . The child window is something like 'http://yahoo.com' which is out side html. I need to refresh the parent window when the child window is closed.
I have an HTML page where I am opening a child window using window.open. the child window is something like yahoo.com. I want to refresh the parent window when the child window is closed.
I'm triing to write script that close popup window, when user click outside the popup. Script below is working fine in firefox (v1.0.3), but not in IE.
I tried also to print hello but still the same problem firefox OK IE not. I think the problem is in event capture, but I can't fix it.
My script: fotowin = window.open("", "foto", "width =100,height =100,location=no,menubar=no,directories=no,toolbar =no,scrollbars=no,resizable=no,status=no");
fotowin.onblur = closeWin; if (fotowin.captureEvents) { fotowin.captureEvents(Event.BLUR); }
function closeWin() { fotowin.close(); //fotowin.document.write("hello"); }
I have aded window unload event handler to my code. my page calls some function that takes few secs and page then loads in 5-6 secs. while ths page is loading, if user clicks 'x' on browser window, then code inside unload event handler doesnt get executed. if user waits for page to be loaded fully and hten clicks 'x', then unload event handler gets executed. but i want if during loading user decides to click 'x' button, then also unload handler shold get exucted.
I am pasting a sample code that simulates my situation:
I need to fire an event from a div when div come to a screen window of user mean as when he scroll down the page then which ever the div comes it should fire an event for example say i have a page in that page i ahve 50 div and each div have 50 images so now say on page load 1st image is load, now when i scroll down and as soon as second dive come to screen second image get loaded so i need to know how i came to know that particular dive come in screen
<select id="aSelect"> <option value="0">a first option</option> <option value="1">a second option</option> <option value="2">a third option</option> <option value="3">a fourth option</option> </select>
but this doesn't work in IE. i've also tried to wire these up manually: document.body.onchange = function (e) { alert('foo); }; and document.onchange, but those don't work either. what's the story here (other than the fact that IE is sucking balls)?
I am using window.unload for some use case in my code. But windows.unload fires on every event. I know to controller it on event like button click or link, but how do I prevent Unload event to fire on refresh or back button event?
If I use a window opener to open a new window, is there a way to detect that the new window is finished loading before carrying out some other directive in the opener window? Can I access the remote window's onload event from the opener window? I need to know that the website has loaded before moving to the next page. something like:
I am trying to add a window event listener on some links in a loop instead of doing them one by one. I've tried
function setListeners (){ for (var i = 0; i < document.links.length; i++) { src=document.links[i].href; document.links[i].onmousemove=changeIframeSrc(src, 'solid',1, event); document.links[i].onmouseout=changeIframeSrc(null,'none',0,event);
I've got a script which is called by a keypress event, something like this:
<html> <head> <script type="text/javascript"> function respondToKey(e) { keyPressed = String.fromCharCode(e.which); if(keyPressed == 'g'){ alert('you pressed the g key'); window.open('http://google.com'); } }
</script> <title>Untitled</title> </head> <body onkeypress="respondToKey(event)"> hit the g key to open a google window </body> </html>
when you hit the right key, the alert appears, but the window.open() never happens. There's not even a message in the Error Console, just nothing.
Is this a security feature? Any way I can get around it? And, if it's a security feature, is the fact that it fails silently with no error message also a security feature? Because it's rather annoying.
how to handle window close event in all aspects? i.e. when window is closed using close button alt+f4 and closing the window by right clicking on the task bar