Using An Object Method As EventListener In IE?
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
ADVERTISEMENT
Oct 5, 2010
13 line causes this exception. Function is called insied of ready() handler. function renderGridSystemRecursively(scheme, container){
[Code]...
View 2 Replies
View Related
Mar 10, 2011
I am trying some simple things with javascript and trying to use it in a object oriented way. However I am now facing a problem in which I can't access an object variable from an object method. I am using jQuery.
My code is as follows;
Code:
My problem is that the variable msg1 does not work when accessed from function called from the jQuery get function. I get the message undefined. Therefore I am wondering, is there a way how I can access msg1 of my object instance from the get function of jQuery?
View 1 Replies
View Related
Nov 19, 2011
I just got this script for a countdown on a website and I got it to work locally but when I upload it to the server i get the error "index.html:22 Uncaught TypeError: Object [object Object] has no method 'fancycountdown'".
I have checked to make sure all other javascript files are loading and they are and I can't figure out whats wrong. You can see it [URL]
View 2 Replies
View Related
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
View Related
Aug 12, 2009
I have a Class name Merkzettel.
[Code]...
and addClickEvent sets the onclick attribute of above mentioned DIV. and in addClickEvent I am explicitely mentioning the name of class object. This means every time I create a Variable with another name I have to Change this function also.
View 3 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
Aug 4, 2011
Code:
var testi_box = {
spread: function(num) {
var main_obj=document.getElementById('testis');
$('.bg').stop().animate({opacity:1},800);
$(main_obj).stop().animate({height: 420}, 800);
var objs=main_obj.children;
[Code]...
So, I have this object that is set to fire its method the moment a user hovers their mouse over a particular div on my page. IT works just fine in all other browsers but IE7 or below. When i look at the error in IE it says that testi_box is undefined. But clearly it is defined. So, I'm lost. Is there something that I am missing?
View 1 Replies
View Related
Sep 30, 2006
i'd like to know objects properties and/or methods.
saying i do have an object "o" being part of the dom (a div or an ul...)
how could i list (introspection) all the properties and methods attached
to this object ?
i know it is possible in javascript but don't remeber how to ...
View 6 Replies
View Related
Oct 16, 2006
I want each instance of an object to be able to listen for input events.
When the event occurs, a method of the object should be called, such
that "this" is in scope and refers to the object instance.
Is this possible? Example:
function MyConstructor(element)
{
//element is some HTML element
this.addListeners(element);
this.foo = "Bar";
return this;
}
MyConstructor.prototype.addListeners = function(element)
{
element.addEventListener("keypress", this.doSomething, true);
}
MyConstructor.prototype.doSomething = function(e)
{
alert(this.foo.length); //Error: this.foo has no properties
alert(this);
//shows the HTML element that triggered the event
}
Is there any way to get "this" to refer to the object in the event listener?
View 6 Replies
View Related
Jun 25, 2009
I found very difficult to call a method outside his scope.For example I have 2 files js
myFunction.js
init.js (where I initialize all my page)
[init.js ][code]....
I tried many syntax in order to call the method outside its scope
$.getX();
$(function(){getX()});
$().function().getX();
$("myHtmlObj").click(function(){getX()});
View 7 Replies
View Related
Oct 8, 2011
i m in trouble i made some piece of code , i've used setInterval() like this way
[Code]...
View 14 Replies
View Related
Apr 9, 2009
I have a question about OOP Javascript...
How can you call a parent method from a child object?
for example...
Am i using the right way of making an object? prototypal vs classical?
View 1 Replies
View Related
Sep 22, 2009
I have this below code snippet
I have an object myscript and from within the method validate, i want to call the method init. so is there there anyway that I can call the method init without having to prefix like this: myscript.init();
I tried this.init(); but it's not working
Code:
View 15 Replies
View Related
Apr 7, 2010
This is the first time i'm really using javascript objects (well the first time i've written my own one) so the problem is probably a very simple one...
I've got this:
Code:
When i change the country from the dropdown box i get an error "hometown.setCities is not a function" but the thing is that i can call this in other ways eg from the address bar (javascript:hometown.setCities()) and it works perfectly.
View 5 Replies
View Related
Jun 24, 2002
I'm trying to build a Validation object, where you pass an object id and event name in the constructor. Then, you call an add_rule method to add validation rules. The constructor code looks something like:
function Validation(id, event, ...)
{
this.object = document.all[id];
this.event = event;
var obj = this.object;
obj[event] = this.validate;
}
So the actual validation function is dynamically bound to the appropriate event. The problem is that when the validate method is called, "this" no longer refers to the Validation object; it refers to the object to whose event it was bound. So, for instance, in the following code, the validate function's "this" refers to frmSubmit, not objValidate:
objValidate = new Validation ("frmSubmit", "onsubmit", ...);
Of course, I need to refer to the actual validation object's properties, but I can't figure out how. Any suggestions?
View 1 Replies
View Related
Nov 2, 2006
I'm trying to write a little script that disables the submit button on a form, changes the text of the button, and then submits the form.
Can anyone tell me why this works ok:
<input type="button" value="Submit" onClick="this.disabled=true;
this.value = 'Submitting...' this.form.submit();">
But when I try to make a function it doesn't work:
<script language="JavaScript">
function DisableButton(b) {
b.disabled = true;
b.value = 'Submitting...'
b.form.submit();
}
</script>
<input type="button" value="Submit" name="submit"
onClick="DisableButton(this);">
When I try this the button text is changed and the button is disabled, but the form doesn't submit. In IE I get an error that points to theline that says:
b.form.submit();
and the error:
Object doesn't support this property or method
What's the difference between doing this code directly in the onClick event and doing it in a function?
View 4 Replies
View Related
Nov 12, 2010
I am trying to use some really simple jquery in a rails 3 app. I am trying to get a function to run whenever a rails 3 js callback is fired, the function is to add or remove css classes from link elements. But so far I keep getting errors in the console (chrome) stating that the object defined by my css selectors doesn't have the addClass and removeClass methods.Here is my code:
$(function($) {
var resetArtistTabStates = function () {
$("#artist-tabs li a".addClass("current"));
[code]....
The ajax:success event come from rails.js jquery file, which contains the following:
callRemote: function () {
var el = this,
method = el.attr('method') || el.attr('data-method') || 'GET',
[code]....
View 2 Replies
View Related
Feb 27, 2010
There's something I can't understand. If I do:
Why does jQuery return elem1 and not the created element ? Returning the created element does much more sense to me since:
a) I already got a reference to elem1 if I need to do further manipulation.
b) I got a references to the 'div' element I've just added.
The way jQuery does it, I'll never get a references to the element I've added.
Can anybody clarify this for me? Is it a 'jquery way' to work this?
View 6 Replies
View Related
Dec 24, 2011
I'm trying to send my array object through ajax using the jQuery .get method, but when it sends, ids show up as multiple parameters and I'm not sure if that's the way to do it.
Here is my code:
var val = [];
$(':checkbox:checked').each(function(i){
val[i] = $(this).attr('id').substring(6);
});
$.get("/assets/ajax/pm_change_status.php", { s: sess_id(), 'ids[]': val } );
View 6 Replies
View Related
Jun 13, 2004
I am trying to call a ActiveX object from JSP using the ActiveXObject method in javascript. I have a dll filed named Patchgenerator.dll which is registered and assigned a prog id "Patchgenerator.PatchGen.1" which is being passed as an argument to the ActiveXObject method. Below is the code i am trying to execute..
[Code]...
When i write the above code and save it as an html file it works fine..the activex object is created and the methods are called , but when i copy the same code to a file and save it as jsp file under webapps folder under tomcat it doesnt work and reports a javascript error with the error being: Automation server cant create the object at line : var SSOObj = new ActiveXObject("Patchgenerator.PatchGen.1");
View 6 Replies
View Related
May 12, 2010
I am creating an application that uses as much Object Oriented code as I could (mostly to learn it).
I have an object called 'photo' that contains two Image() objects 'fullImage' and 'thumbnail'. All is fine and dandy, I can read the thumbnail and the full image, and their associated properties just fine.
But what I can't seem to do is make the thumbnail's onclick event refer to one of the object's methods.
Here is a greatly simplified version of the object's code.
Code:
So, the thumbnails div gets populated with the thumbnails fine. But for the life of me, I cannot figure out how to make the onclick call the photo object's "editPhoto" method.
Will the way that I am creating the objects using the same name for each one, result in only the last one created being accessible. If so, do I need to create an array of objects so I can uniquely identify each one?
View 3 Replies
View Related
Nov 17, 2010
appears only in IE: l2 = obj.parentNode.getElementsByTagName("select")[0].value; --> object does not support this property or method var l2 = obj.parentNode.getElementsByTagName("select")[0].value;
View 4 Replies
View Related
Apr 1, 2010
I am trying to preload some sounds for a website I am working on... Originally I used the embed tag but that caused problems in Opera and did not validate... So I've switched to the object tag which now works in everything except IE8...
<object id="sound_lock" class="embedded" data="sounds/iphone/system/iphone_sound_lock.wav">
<param name="autostart" value="false" />
</object>
I had to put in a class to hide the sound files because tey were appearing with controls in Opera...
.embedded { visibility: hidden; }
Lastly here is the javascript code that plays the sound when required... Works in latest FF, Opera, Safari and Chrome but not in IE8... IE8 generates an 'object doesn't support this property or method' error...
var thisSound=document.getElementById(soundObj);
thisSound.Play();
I'm assuming this is because IE8 can't get the id from the object tag but can't find a work around... I want to make sure all the code validates appropriately so I am trying to avoid the embed tag..
View 6 Replies
View Related
Oct 13, 2011
I have defined a method in an iframe named as refresh1().In the iframe we are showing records in a table.on clicking a record of table or you can say row a showmodal Dialog object will open which shows the info of clicked record.I want to call refresh1() method onclick of save button whic is defined in modal dialog.I have triedparent.window.dialogArguments.refresh1() but it is not workin.
View 2 Replies
View Related