Window.addEventListener( "blur" , Function()
Jun 15, 2011I have this piece of code:
Code:
I don't understand it ... it should work :-? ...
I have this piece of code:
Code:
I don't understand it ... it should work :-? ...
I've been using window.onerror to capture and report JavaScript errors
from other users for debugging an application I've written. But I've
run into a strange issue with Firefox and window.onerror.
It seems that any code that executes, having originated from an
"element.addEventListener", causing an error does not activate
"window.onerror". But it does at least show up in Firefox's JavaScript
error console. Internet Explorer doesn't appear to suffer from the
same issue when it uses it's equivalent "element.attachEvent".
Does anyone know why this is and if there is any workarounds or if it's
possibly a bug? Code:
On my site we have image galleries that pop up over top of the page in a higher z-index and position:fixed, and another div between the gallery and background with opacity set to about 85%. The image gallery div has a close button, and I was asked to make the gallery also close by pressing ESC, so I added this:
igevt=function(evt){checkclosegal(evt)}
window.addEventListener('keypress',igevt, false)
and checkclosegal:
function checkclosegal(evt)
[Code]....
This works perfectly in Firefox and Opera, but Chrome and Safari don't fire the event (not worried about ie right now - I know it uses attachEvent). Could it have something to do with the gallery being in a higher z-index?
I try to do this:
<head>
<script type="text/javascript">
function uppercaseListener() {
this.value = this.value.toUpperCase();
}
function installListeners() {
var element = document.getElementById('street');
element.addEventListener('change', uppercaseListener, false);
}
window.addEventListener('load', installListeners, false);
</script>
The ERROR:
"The object does not accept this property or metodo"
On my site we have image galleries that pop up over top of the page in a higher z-index and position:fixed, and another div between the gallery and background with opacity set to about 85%. The image gallery div has a close button, and I was asked to make the gallery also close by pressing ESC, so I added this:
igevt=function(evt){checkclosegal(evt)}
window.addEventListener('keypress',igevt, false)
and checkclosegal:
function checkclosegal(evt)
[Code]....
This works perfectly in Firefox and Opera, but Chrome and Safari don't fire the event (not worried about ie right now - I know it uses attachEvent).
I was using this script to learn how to use event listeners and I need to know how to make it work for IE. I keep finding attachEvent scripts that look like they will work, but I get nothing. I've spent several hours finding script after script that simply don't work. I don't know where to turn next. Any script to attach these events to IE?
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "[URL]">
<html>
<head>
<title>Test</title>
</head>
<body><div>
<script type="text/javascript">
if(!Array.prototype.link)
Array.prototype.link = function(f) { for(var Obect1 = new Array(), i = 0, n = this.length, t = arguments[1]; i < n; i++) Obect1[i] = f.call(t, this[i], i, this);return Obect1;};
Array.prototype.linkMethod = function(m) { var n = this.length, args = this.slice.call(arguments, 1);if(typeof m == "string" && n > 0) m = this[0][m];for(var Obect2 = [], i = 0; i < n; i++) Obect2[i] = m.apply(this[i], args);return Obect2;}; .....
A test script like this:
<A HREF="javascript:window.blur()">Blur Window</A>
put the window in the background in IE, when pushed, but it does nothing in other browsers like Chrome, Safari, Opera, Mozilla under Windows.
My real page is loaded from an external program (not the browser), if I dont have anything to tell the user, then I want the page to be "minimized" (or closed).
I am also able to close it in IE, but most people seem to believe that it shouldn't be possiple to close a close a window through Java, when it is not opened by Java.
Do I have other "minimize"/"close" options or how do I make blur work?
I have got a following function:
PHP Code:
function addEvent(obj, type, fn) {
if (obj.addEventListener)
[code].....
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'm creating a script which causes the page to scroll when the mouse is held down within 1/3 of the page height of the window edge. An example can be found at [URL], and is working fine in Firefox, Safari and Chrome, but not in IE. I'm 90% certain this is due to the browser's non-handling of addEventListener, but I'm not sure how to fix this...I've tried the following so far:
[Code]...
What is the practical use window.focus() and window.blur()?
View 2 Replies View RelatedIs there a way to pass arguments to the callback function used inside an addEventListener? I see that I can only list the name of the callback function. For eg, I use this:
var boldLink=document.getElementById('cmtbold');
boldLink.addEventListener("click", rBold, true);
I need the id of boldLink to be accessible from inside the function
rBold()
Every time i click on one of the said elements, it puts "undefined" into the textbox each time i click on an element.it seems to me that the Key_Table[x] is not getting passed correctly. How do i make sure that this is getting passed correctly?Here's my Code:
<script type='text/javascript'>
// Startup Script
if (document.addEventListener) {
[code].....
I'm trying to build a data navigation utility that will allow a central "map" page to control a number of tab pages that are loading individual pages from a large set of HTML. All are local file://localhost/, with localhost popups enabled. (for dev/testing all popups are enabled since firebug 1.3.3 has problems loading localhost .js code) preference to "raise and lower windows" has been enabled I am using firefox 3.0.8 on FreeBSD 6.4
Anyway, I can't get window.focus() and blur() to work between cooperating tab/windows who know each other's names.
Here following are two cooperating mirror tab pages that i'm trying to get working. Have tried a number of combinations of the focus() and blur() calls. Have tried with/without messaging. Messaging works fine.
I have noticed that the calling tab seems to unload/reload as a result of the click event. This still allows the message to get through OK, but I guess the reload could be taking the focus again.
An annoying alert() dialog could of course get focus to the message receiver, but it requires another click to get it out of the way.
The concept of these focus() and blur() calls is so simple, and I've searched all over the web for examples, but nothing seems applicable.
Have also seen that this may be a bug in Firefox.
======== code for "mirror" pages "focus1" and "focus2" follows:
<html>
<head>
<title>test window focus - 1</title>
<script language="javascript">
[Code]....
I know it used to not, but according to the blur() docs page "the domain of the event has been extended to include all element types." Is this true, or do I need to set up an onClick event for the body and check to see if the currentTarget or its parents are the div I'm trying to fire the blur event on?
View 2 Replies View RelatedI would like to open a window "under" the current window (So it doesn't open on top). I think this can be achieved using the .blur function.
So something like:
<a href="#" onclick="openWindow [URL];this.blur();return false;">Open website</a>
(Obviously this doesn't work)
I've seen ways to do it, if I'm using 1 url, but because I have a list of 30 different links, I can't simply use:
Code:
<SCRIPT LANGUAGE="JavaScript">
function goNewWin() {
TheNewWin =window.open("somepage.html");
TheNewWin.blur();
}
</SCRIPT>
Which is why I need something that I can use on each different url individually that opens a new window under the current one.
The following script sets values for various input elements and I want exactly the same function to run for the on blur event of at least two fields. The first half of the script works fine - however when I take the $('#prod_id2unit_price').blur(function() and script it as a separate function and then call it from
$('#prod_id2unit_price').blur(tvf());
$('#prod_id2qty').blur(tvf());
it all stops working -
</script>
<script language="JavaScript" >
$(document).ready(function(){
unitprice0 = $('#prod_id0unit_price').val();
[Code]....
This makes my life a bit easier. After executing this script you should be able to addEventListener on all elements instead of determining if you want to call attachEvent or addEventListener.
Edit: This is the original version. The revised version is below
if (!document.addEventListener && document.attachEvent)
{
Object.prototype.addEventListener = function(eventName, func, capture)
{
if (this.attachEvent)
this.attachEvent('on' + eventName, func);
}
var i, l = document.all.length;
for (i = 0; i < l; i++)
document.all[i].addEventListener = Object.prototype.addEventListener;
window.addEventListener = Object.prototype.addEventListener;
document.addEventListener = Object.prototype.addEventListener;
}
Revised version:
This one is harder to use but it is nicer to the DOM and all newly created objects. The problem with it is that addEventListener will only be available after the page loads.
If you want to use addEventListener from a window.onload script make sure that this code is included in the body, not in the head. document.body.onload is called before window.onload.
Now, only elements that already have attachEvent will get an addEventListener. Elements created with document.createElement will automatically get addEventListener.
function createIEaddEventListeners()
{
if (document.addEventListener || !document.attachEvent)
return;
function ieAddEventListener(eventName, handler, capture)
{
if (this.attachEvent)
this.attachEvent('on' + eventName, handler);
}
function attachToAll()
{
var i, l = document.all.length;
for (i = 0; i < l; i++)
if (document.all[i].attachEvent)
document.all[i].addEventListener = ieAddEventListener;
}
var originalCreateElement = document.createElement;
document.createElement = function(tagName)
{
var element = originalCreateElement(tagName);
if (element.attachEvent)
element.addEventListener = ieAddEventListener;
return element;
}
window.addEventListener = ieAddEventListener;
document.addEventListener = ieAddEventListener;
var body = document.body;
if (body)
{
if (body.onload)
{
var originalBodyOnload = body.onload;
body.onload = function()
{
attachToAll();
originalBodyOnload();
};
}
else
body.onload = attachToAll;
}
else
window.addEventListener('load', attachToAll);
}
createIEaddEventListeners();
I want to preserve a 16/9 aspect ratio to the window after any resize, making the width a function of the height.
As I have a window.resizeTo() inside the window.onresize event function, the infinite loop is served. How may I quit it?
<html><head><title>Title</title><script languaje="javascript">
const c_ra=16/9;
window.onresize = function WindowReSize() {
var myWidth = 0, myHeight = 0;
[Code].....
Today I have been testing the event models from Netscape 4.8 and IE 4
to the current crop of browsers. I'd like to write a small event
library similar in purpose to the Yahoo! UI event library but with less
features and code. The Yahoo! event library is one of the best
libraries in YUI but it still seems to me to have some confused
code...that or I'm still confused.
The Yahoo! UI library focuses on using addEventListener and
attachEvent. However, due to the click and dblclick bugs in Safari a
long legacy event workaround is included to use a Netscape4-type event
model for Safari. Something like this
var listeners = [function(event){}, function(event){}];
document.getElementById('blue').onmouseover = function(event) {
for (var i=0; i<listeners.length; i++) {
listeners[i](event);
}
};
With this above example, multiple handler functions can be fired for a
single event. I imagine that this is an old trick that has been around
for a long time, yes?
With all the new browsers I tested with this legacy workaround, the
listener handlers can use event.stopPropogation() or
event.cancelBubble=true and they work as desired. The handler functions
can also use event.preventDefault() and event.returnValue=false and
they too work. These seem to work because the event object passed to
the handlers is a modern event object and not one from Netscape4.
My question is, if Safari needs this legacy workaround, and the legacy
workaround seems to work in all the browsers that have addEventListener
or attachEvent, then why bother with the addEventListener and
attachEvent functions at all? Why not just use the legacy way for all
browsers and all type of events.?
I'm trying to add a clickevent to an anchor that I created trough DOM.
This his how the code looks:
var oSubLink = document.createElement("A");
oSubLink.appendChild(document.createTextNode("+"));
oCel.appendChild(oSubLink);
oSubLink.addEventListener("click", klapUit(oTabel.id, eigenschappen[2]), false);
It failes at the addEventListener call, saying "No such interface supported" (appears to be one of the two default error messages IE gives when it can't handle your JS :mad: ).
How can I fix this? The solution should work in IE6, FF, Opera, Mozilla and Safari.
Is there a way to send parameters to the function being added to an event with addEventListener. I.E. say you have this function
Code:
function someFcn(i){
alert(i);
}
and I add it to an object.
Code:
someElement.addEventListener('focus', someFcn, false);
Is there a way to send a parameter to someFcn.
For Example I have tried this but it failed
Code:
var someString = 'Hello World'
someElement.addEventListener('focus', someFcn(someString), false);
I have this code:
for(var h:Number=0; h<4; h++){
var Build : Button;
Build = new Button();
Build.height = 20;
[Code]...
I have created and opened a child window called "checkwin" and have written some data to it. If the data is valid, I want the user to click on the 'CONFIRM' button on the child window, at which time I want the "submit()" function for the form on the parent window to be executed. If the data is invalid the user clicks on 'MODIFY' and I want focus to return to a field on the parent form. However, when I click on the "CONFIRM" or "MODIFY" buttons on the child window, nothing happens. Here is the code:
checkwin.document.write("</td></tr><tr><td align='right'><input type='button' value='CONFIRM'
onclick='opener.document.personnel_form.submit()'></td><td></td><td><input type='button' value='MODIFY'
onclick='opener.document.personnel_form.first_name.focus()'></td></tr></table>")
When you use addEventListener (or addEvent in IE) to call an object
method, does it call it with the correct this parameter?
The ECMAScript reference has a lot to say about the caller using
Function.prototype.call or Function.prototype.apply and passing the
correct this pointer for the context, but how does addEventListener
determine the correct this pointer. Or does it just punt and pass the
global context, thus making it impossible to refer to the object this
in an object method used as an event listener?
Is it possible to add events using addEventListener to multiple radio buttons with same id ?
<input id="radId" type="radio" value="0" name="radioname">No
<input id="radId" type="radio" value="1" name="radioname">Yes
I tried to attach event using document.getelementByID BUT it always picks the first radio button.