Event.observe Prototype Iexplorer Problem
Jul 5, 2007
I can't get out of this riddle and Google seems can't help me.
The problem is that this code doesn't work in iexplorer while it's
perfect in other browser (didn't check in safari):
<html>
<head>
<script src="include/js/scriptaculous/lib/prototype.js"></script>
<script src="include/js/scriptaculous/src/scriptaculous.js"></script>
<script type="application/javascript" language="javascript">
function goofy(id) {
var linkList = $(id).getElementsByTagName('a');
var tmp;
var j;
while (tmp=linkList[j++]) {
if (tmp.rel=='bar') alert ('yes');
else alert ('no');
}
}
</script>
</head>
<body id="corpse">
<a href="http://www.foo.bar" rel="bar">foo</a>
<a href="http://www.foo.bar">foo</a>
</body>
<script type="application/javascript" language="javascript">
var init=goofy('corpse');
Event.observe(window,'load',init);
</script>
</html>
Now, what's the point? I'm sure it isn't a prototype problem so it's my fault, but where? Do you have any hint? Do you have some offence for my incompetence (but only in combo with hint)?
View 2 Replies
ADVERTISEMENT
May 31, 2006
I have the following script, which uses prototype.js and is called when the page loads:
function getAllDefs() {
allDefs = document.getElementsByClassName('def');
var defs = $A(allDefs);
defs.each(function(def){
Event.observe(def, "click", listElement, false);
});
}
It adds an onclick event handler to each element with a 'def' class. Clicking the element then calls the "listElement" function, defined as follows:
function listElement(e) {
alert(this.nodeName);
}
This works great in Firefox, returning "SPAN" for the element. However, in IE6, "undefined" is returned. I've tried nodeType and innerHTML as well, and all are "undefined" in IE6. Anyone know what the deal is here with IE? It's somewhat hard to tell since IE's responses are so vague.
View 3 Replies
View Related
Feb 27, 2009
I'm using the Prototype JS framework. why this doesn't work in IE6?
Code:
document.observe('dom:loaded', function(e){alert("hello world");});
It should just fire off an alert once the page loads, but does nothing, no errors either. Of course it works fine in Firefox.
Test it out here (the alert message is slightly different but everything else is the same, you'll want to remove the spaces in the url of course): www-stage . emd . wa . gov / dev / kids / dev / prototype_test . htm
View 3 Replies
View Related
Jun 2, 2009
I'm trying to make the cursor focus on a certain input element when someone hits a certain key combo (such as Shift+S). Does anyone know how you attach a listener like that and bind it to a key combo?
View 1 Replies
View Related
Dec 5, 2006
I have a strange problem using Internet Explorer.
My page has a table included in a <DIV>
I have a checkbox that shows the div when checked
and hides it when unchecked.
var division = document.getElementById("passport") ;
Then I use
division.style.visibility = "visible" ;
or
division.style.visibility = "hidden" ;
Everything works perfectly under FireFox or Safari showing or
hidding the table.
BUT, in IExplorer 6 or 7, just checking the checkbox doesn't
change anything. You have to first click on the actual division
position to make it appear. Same for unchecking: click on the
displayed table and it will disappear. Code:
View 2 Replies
View Related
Mar 12, 2007
I am wondering why the following works, on IE6, but with an error : "Not
implemented".
function TEST(){}
TEST.prototype.Initialize = function()
{
var mImage = new Image();
var mDate = new Date();
var start = mDate.getTime();
mImage.onload = this.Alerting(start);//WORKS with ERROR "Not implemented"
//mImage.onload = function(){this.Alerting(start);}//ERROR "Object doesn't
support this property or method"
mImage.src = "winxp.gif";
}
TEST.prototype.Alerting = function(i_string){alert(i_string);}
var mTest = new TEST();
mTest.Initialize();
Can anybody guess why?
View 11 Replies
View Related
Oct 29, 2010
I'm working on a unit test for a javascript library that has several handlers. I wish to fire those handlers in a "natural" way, by raising an event that gets caught. I am having trouble creating an event that gets caught in Firefox.I do development in Firefox to take advantage of Firebug, but the software is for a closed intranet and IE 7 is the required browser (we support IE 8 insofar as we force it to IE 8 mode). This policy predate my hire, I'm trying to get the software to a browser agnostic state - first I have to replace an ActiveX object known as MeadCo Script X - but that's a whole other issue.Anyway I need to raise events, specifically onchange events in Firefox. I have this so far...
Code javascript:
function fire(el, ev) {
el = $(el);
if (typeof(el.fireEvent) != 'undefined') { // IE
[code]...
Prototype library is in use for this project, though I haven't used it for this particular corner case.
View 1 Replies
View Related
Aug 30, 2010
I need to know how to add an event to a button. The specific issue is that I want to add an event which is a prototype function of a class. Consider the following as an example:
MyTestClass = function() {
this.firstName = "Pete";
this.lastName = "Johnson";
[code]....
View 2 Replies
View Related
Sep 7, 2010
still have a problem with the following code:
<ul>
<li><a class="open-page" href="/somewhere.html">link1</a></li>
<li><a class="open-page" href="/elsewhere.html">link2</a></li>
</ul>
[Code].....
i also tried to use .live() - nothing. the links where opened by thecommon way browser handle this anchors - follow the link ;)
how to handle these added elements?
View 8 Replies
View Related
Nov 25, 2011
According to ECMAScript, the root of the prototype chain is Object.Prototype. Each object has an internal property [[Prototype]] that could be another object or NULL.... However, it also says that every function has the Function prototype object: Function.Prototype, it confused me, because a function is an object, for a function object, what is its function prototype and object prototype..For example:
var x = function (n) {return n+1;};
what is the relationships of x, Object.Prototype and Function.Prototype
View 5 Replies
View Related
Dec 14, 2009
I am trying to get to the bottom of javascript object, prototypes etc. I have a fairly good grasp of it, but I get confused the closer I get to the base object.prototype. FIrst of all, I was under the impression that all objects descend directly from Object. But some objects (like Array) seem to inherit properties and methods from the function.prototype. So does this mean that the chain is like this:
object -- function -- array Second, I noticed (on the mozilla javascript reference site that object.prototype inherits properties and methods from function.prototype and vice versa!? How can this be? I must be missing something important about understanding the chain?
View 24 Replies
View Related
Jan 15, 2006
I was trying some Prototype experiments and got Event.observe to work with
"click" and "change" events.
I wanted to do something similar with "key pressing". For example, detect
when somebody pressed the RETURN and/or ENTER key inside a particular text
field.
I couldn't find any docs on this. Does anybody have an example snippet?
View 3 Replies
View Related
Aug 24, 2005
I can use "with" like this:
function MyObject(message)
{
this.message = message;
}
function _MyObject_speak()
{
alert(this.message);
}
with (MyObject)
{
prototype.speak = _MyObject_speak;
}
I was wondering why I can't use "with" like this:
with (MyObject.prototype)
{
speak = _MyObject_speak;
}
View 8 Replies
View Related
Jul 23, 2005
One of the complaints about prototype.js (google for it if you're not
familiar with it) is that it's poorly documented. I have this inkling
that the key to understanding prototype.js is in the bind function.
The problem with Javascript is that the "this" operator is poorly
overloaded and it is often hard to understand in the context of
object-oriented javascript
So, let's start with the definition:
Function.prototype.bind = function(object) {
var method = this;
return function() {
method.apply(object, arguments);
}
}
As I read this, it states that all functions (which are themselves
objects) will, in the future, have an associated method called "bind".
The function() function, so to speak, simply instantiates a Function
object with the parameter list and then evals the statement, sticking
the resulting execution-tree in the current code frame.
The "this" there refers to the function object associated with the call
to bind(), right? But the word "arguments" there refers to the
arguments passed to the function object *generated by* the call to
bind().
In every example within prototype.js, bind() is called either in a
constructor or within a method contexted to a javascript object, and is
always called with "this" as its argument, e.g.:
this.options.onComplete = this.updateContent.bind(this);
As I read the code it seems to be stating that the "this" object
referred to within bind()'d functions are being coerced into always
referring to the current instantiated object.
But isn't this always the case anyway? Is this a rather confusing
attempt to ensure "this" purity whereby the call
method.apply(object, arguments)
is forced to always have the reference to the containing object present?
I think I've got it. Bind() generates uniq functions that contain live
references to the objects to which they belong, such that the function
object can then be passed to setTimeout() or onMouseOver(), handlers
that accept functions but not objects.
View 8 Replies
View Related
Mar 15, 2006
Lets say we run: window.alert = function() { };
Is there anyway to 'restore' the original alert() method or is it gone
forever?
I know you can do window.alert = Window.prototype.alert, but lets say
you also set Window.prototype.alert = function() { } or lets say we're
in Opera, which doesnt have a Window "class".
View 3 Replies
View Related
Jun 5, 2006
I would like to set up an event observer outside of an object, so I
can't use this.bindAsEventListener. How can I pass the correct object
reference?
I tried something like this, and various other variations, but no luck.
This works when I set it up from inside the object, using "this.",
Event.observe(targetId,'click',targetId.select.bin dAsEventListener(this),false);
View 28 Replies
View Related
Jan 11, 2007
I wanted to add an object as a prototype to separate my methods more
nicely, however, I ran into a couple of problems. Apart from the
obvious "scope" issues I found that any instances of my class shared
the objects methods and properties.
I realise (now) that this is actually how prototypes work, they share
functions and objects rather than create new instances of them for
every "class", but is there any way around it? (or shouldn't I be doing
things like this at all?) Code:
View 2 Replies
View Related
Jan 23, 2007
I am working on my own pop up calendar, mainly because the one I am currently using crashes the Safari browser at times.
So, I want to verify that what I am doing will work, in that I want to be able to have multiple calendars open at the same time, each independent of the other.
So, I start it off with:
var Calendar = {
dateSelected: null,
topPos:null,
leftPos:null,
somefunction:function(e) {
...
}
};
If I create more than one calendar object, will they have their own variables, in that the dateSelected, topPos and leftPos will be unique to that instance?
Or, is there a better way to do this, that is cross-platform.....
View 8 Replies
View Related
Mar 4, 2007
In my research in the javascript language I have encountered problems
with implementing prototype inheritance while preserving private
methods functioning properly. Here is an example: Code:
View 2 Replies
View Related
May 16, 2007
I want ask you if, for a web portal/application, is better prototype or Jquery? I don't want to innesc some type of flame, but after the announce that drupal use JQuery and that the new Wordpress
2.2 use Jquery I ask myself if my choice of use prototype.js is the bettere choice.
View 5 Replies
View Related
May 17, 2011
I have <div id ="changeable"> with some html in it. I have a link that calls the function to replace the info in the div. The problem is that the "creative_development.inc" file is added to the top of the div and does not replace the content. How do I replace the content, and not just add content?
View 1 Replies
View Related
Nov 20, 2007
I'm trying to make an addEvent function that will automatically attach itself to the object using a class.
My question is how can I add the function so when I write obj.addEvent("click",myfunction); it will add the event?
Here's my current function:
this.prototype.addEvent = function(type,fn)
{
if(window.attachEvent)
this.attachEvent("on"+type,fn);
else if(window.addEventListener)
this.addEventListener(type,fn,false);
}
View 4 Replies
View Related
Dec 13, 2007
I need help to workaround the following problem:
First, about the environment:
- The web pages automatically generated.
- Pages can be inserted to each other
- When a subpage to be inserted is being generated, it does not know will it be inserted or not.
- That because each subpage uses the <script src=...> tags to load the script it needs.
- in the external script files I'm trying to protect it from repeated execution checking (if(){}) the value of a variable which is created after in the script.
Everything worked fine until I tried to use the .prototype to declare the method of my objects.
In the Internet Explorer, I got "Object does not support this property or method", on the access to a prototype function, because the prototype of my object was deleted by itself after the second load of the external script. Code:
View 4 Replies
View Related
Apr 9, 2006
This function will return an array of the elements in a page that contain a certain attribute, you can also give it a value that the attribute has to match, a tag name that the element has to match and a parent element.
I know there are other functions for doing this, but this one is written for use with the prototype (http://prototype.conio.net/) JavaScript library, in fact its really just a modified version of the getElementsByClassName() function that’s part of prototype.
document.getElementsByAttribute = function(attribute, value, tagName, parentElement) {
var children = ($(parentElement) || document.body).getElementsByTagName((tagName || '*'));
return $A(children).inject([], function(elements, child) {
var attributeValue = child.getAttribute(attribute);
if(attributeValue != null) {
if(!value || attributeValue == value) {
elements.push(child);
}
}
return elements;
});
}
Usage is pretty simple, this will return all elements with a width attribute:
View 2 Replies
View Related
Nov 13, 2005
I try to get a xml-response with prototype. for e.g. i have the following code:
<html>
<head>
<title>Test Ajax</title>
<script src="prototype-1.3.1.js" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
var getXML = function()
{
var myAjax = new Ajax.Request(
"bsp.xml",
{
method:'GET',
onComplete:showXML
}
);
}
var showXML = function(r)
{
var names = [];
var root = r.responseXML.getElementsByTagName('personal').item(0);
// root
for (var i = 0; i < root.childNodes.length; i++)
{
var node = root.childNodes.item(i); // mitarbeiter
names.push(node.childNodes.item(1).firstChild.data);
}
$('xml').innerHTML = names.join("<br />");
}
//]]>
</script>
</head>
<body>
<p>
<a href="#" onclick="getXML();return false;">TEST</a>
</p>
<div id="xml">
</div>
</body>
</html>
xml-Data:
<?xml version="1.0" ?>
<personal>
<mitarbeiter>
<vorname>John</vorname>
<name>Brown</name>
</mitarbeiter>
<mitarbeiter>
<vorname>Matt</vorname>
<name>Blue</name>
</mitarbeiter>
</personal>
This works fine in IE but in Geko-Browser i got nothing back, because this browsers build the DOM with linebreaks and whitespace. Do you have any ideas what is wrong in my code and how to get propper DOM?
View 1 Replies
View Related
May 16, 2006
Having read through Sergio Pereira's Prototype documentation I came across the grep command within Enumerable object.
This is something that looks very interesting. Such as being able to quickly select only the elements you want using a regular expression.
But for the life in me I can seem to get it to work.
Anyone a bit more up to speed with Prototype care to have a look?
var elementList = Form.getElements("just-a-form");
nodes = $A(elementList);
var localElements = nodes.grep( /image/, function(node){
return node.id
});
View 4 Replies
View Related