EventListener Issue
Sep 8, 2007
Can you see whats wrong with my code? I get the following error:
element has not properties.
function test()
{
document.getElementById("statusbar").innerHTML = this.id;
}
// Handles all elements
function init()
{
//var elm_right = document.getElementById("right");
var element = document.getElementById("left");
element.addEventListener('click', test, false);
}
window.onload=init();
View 4 Replies
Aug 1, 2009
I'm working on a drag and drop HTML editor, in which blocks can be positioned. I need to build a controller which listens to mouse events and takes appropriate action (a state machine). The system is built using prototypes and objects. The Controller class looks like this (I removed some methods for simplification):
Code JavaScript:
/**
* Creates a controller for a document
*/
function Controller() {[code]....
The method 'handleMove' is entitled to handle a mouse move on the overlay. Because the 'this' keyword would not point to the Controller object I've written a wrapper according to the W3C EventListener interface (http://www.w3.org/TR/DOM-Level-2-Eve...-EventListener). This wrapper holds a reference to the object in which the method resides that's handling the event, so that the important 'document' attribute can be reached. This document holds the document that is being edited (it's of a custom type, and not to be confused with the document as in document.body)
The problem I now have is as follows. IE doesn't seem to be able to work with event handlers following the EventListener interface, but just functions. I need to get the object's reference there as well though, but this can't be done using an anonymous function, as at the moment it will be run it will be in a different scope, and not be able to reach the controller any more.Just using a global holding that reference variable, a method I used before, is not sufficient, as there may be multiple instances of the editor running on the same page.I have no problems in FFox, Opera, and Safari. Just IE because it uses an alternative event listener model.
View 2 Replies
View Related
Nov 15, 2006
I've got to write some javascript to listen for a select 'change' event. Unfortunately, the select box has an onchange event as well. For example:
<select name="test" onchange="document.form.submit();">
Here's my event listener:
function handle_submit() {
return false;}
function addListeners() {
if (document.addEventListener) { document.form.test.addEventListener('change',handle_submit,false);
}}
window.onload = addListeners;
Now, the event listener does capture the event, but I want to cancel the onchange event within the select box. Is that possible?
View 1 Replies
View Related
Jul 9, 2010
I got the "loading external pages" overlay working just fine from the examples. My project calls for me to open an external overlay but we don't have control over the trigger point. The content is being injected into our pages via an external scripts. So I created an event listener with JQuery to listen for any clicks that occur to a specific link, this works just fine. What I've been struggling to do is open up an external overlay via my listener. I've tried creating a custom function called showOverlay that will do the real work but no luck. Is it possible to trigger an external Overlay via eventListener or do I have to take a different approach?
This is my eventListener.
$('#ExternalLinkReadID a').click(function() {
var id = $(this).attr('href');
alert("before: " + id);
$(this).showOverlay();
alert("after");
});
<a href="readreviews.jsp" rel="#overlay" style="text-decoration:none">
<button type="button">Reviews</button>
</a><!-- overlayed element -->
<div class="apple_overlay" id="overlay"><a class="close"></a>
<!-- the external content is loaded inside this tag -->
<div class="contentWrap"></div>
</div><!-- make all links with the 'rel' attribute open overlays -->
<script>
$.fn.showOverlay = function() {
// if the function argument is given to overlay,
// it is assumed to be the onBeforeLoad event listener
$("a[href]").overlay({
mask: 'lightgrey',
effect: 'apple',
onBeforeLoad: function() {
// grab wrapper element inside content
var wrap = this.getOverlay().find(".contentWrap");
// load the page specified in the trigger
wrap.load(this.getTrigger().attr("href"));
}});};
</script>
View 6 Replies
View Related