473,403 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Trouble getting events set with IE

I'm using the Prototype library for ajax calls. (Yes, I'm aware of the
discussions about prototype lately). Perhpas it's the library that's
causing problems, but I'm more suspct of my own code at this point in
my javascript learning curve.

Here's the test page with inlined javascript:

http://hank.org/demos/ajax3.html

Works in Firefox and Opera. Safari sees the onclick events, but then
runs the default action (follows the link). IE doesn't run the event
handler at all, although as seen with the alerts, it's running the code
to set the events.

The inital goal was to separate the html from the javascript -- that
is, avoid using inline onclick events in the html.

The code is suppose to find all elements with class "ajaxtarget" --
that is the container that is replace by the ajax call. The events to
set are then found by looking for class="ajax" within that outer
target.

Upon an oclick event (before making the ajax call) the code removes the
events. From what I've read that's needed to keep IE from leaking
memory. After the DOM is updated the process of adding the onclick
events is repeated to reset the events.

At this point I'm looking for help to get the code working, if
possible, with IE and Safari.

Thanks,

Apr 4 '06 #1
10 1455
Can you trim the code down and reproduce the problem?

Peter

Apr 4 '06 #2
Yes I can, http://hank.org/demos/ajax4.html.

var my_event = function(e) {
alert('got click ');
Updater.click(e,el);
e.preventDefault();
return false;
};

So, on IE the first alert is called, but not the Updater.click() call.

Apr 4 '06 #3
wh*******@gmail.com wrote:
Yes I can, http://hank.org/demos/ajax4.html.


You could also get rid of a bunch of all styles and a bunch of html
tags and still have the problem? None of this stuff should be causing
the problem so removing it will help isolate things.

You mentioned that there was a problem with Safari. I cut the code down
even more and just tried the following in Safari 1.3.2 on OS X 10.3.9
and it worked fine. Also works in Firefox 1.5. By fine I mean I saw
both alerts.

If this works in your browsers try building the code back up until it
breaks. This will give better clues to which line is causing problems.

Peter
<html>
<head>
<script type="text/javascript" src="proto/prototype.js" ></script>
</head>

<body>
<a id="foo" style="cursor:pointer;">Click me!</a>

<script type="text/javascript">
var Updater = {
init: function () {
var el = $('foo');
var my_event = function(e) {
alert('got click ');
Updater.click(e);
};
Event.observe( el, 'click', my_event, false );
},

click: function(event) {
alert('received click on element href=' +
event.currentTarget.id );
return false;
}
};

Updater.init();

</script>

</body>
</html>

Apr 4 '06 #4
wh*******@gmail.com wrote:
I'm using the Prototype library for ajax calls. (Yes, I'm aware of
the discussions about prototype lately).
My sincere condolences nevertheless.
Perhpas it's the library that's causing problems, but I'm more suspct of
my own code at this point in my javascript learning curve.


Your code is syntactically correct. So either the library is buggy
(surprise!), or you are using it wrong. The best thing you can do
at this point of your learning curve is to avoid code that you do not
understand. (Which in this case is code that not even experts fully
understand, because Prototype is simply a load of completely
undocumented, unsupported, clueless junk.)
PointedEars
--
Ceterum censeo Prototypem esse deletam.
Apr 4 '06 #5
No, that does not work in IE. It's basically the same code as my
previous post. In IE I only see the first alert(), but in firefox I
see both.

http://hank.org/demos/ajax4.html

Apr 4 '06 #6
Of course, it's hard to argue logic with someone with pointed ears, but
the code is only using Event.observe and, as you must have seen from my
previous post, the event is working (so Event.observer is working)
because the first alert() displays, then then the second alert()
fails. So in this case it does not seem to be related to any junk in
Prototype. Not that Event.observe() does anything complex.

But, let's assume you are right anyway.
http://hank.org/demos/ajax5.html is a version without prototype that
also doesn't work in the same way on IE. "Updater.click(e)" is perhaps
not the correct way to call that when using IE?

Or maybe it's just my version of IE? I only have 6.02/Win98 and
5.2/Mac to test on.

Apr 4 '06 #7

wh*******@gmail.com wrote:
No, that does not work in IE. It's basically the same code as my
previous post.


That means the problem is closer to being isolated since my code was
less than yours. Keep removing code until the problem dissappears.
After add things in and experiment to see what causes the problem

Peter

Apr 4 '06 #8
Ok, I reduced it down to:

<script type="text/javascript">
alert('it works!');
</script>

And that seems to work.

I'm not sure what you want me to remove at this point. It's down to a
single call that's failing.

var Updater = {
init: function () {
var el = $('foo');
var my_event = function(e) {
alert('got click '); // *** This happens ***
Updater.click(e); // *** This doesn't happen in IE ***
};
Event.observe( el, 'click', my_event, false );
},

click: function(event) {
alert('received click on element href=' +
event.currentTarget.id );
return false;
}
};

Apr 5 '06 #9
Ah, ok. IE doesn't pass the event to the event handler.

e = e || window.event.

Apr 5 '06 #10
No, that would be wrong. It was unsuported methods in IE.
End of thread. ;)

Apr 5 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Bill | last post by:
For my personal use I am accessing a railway timetable page, parsing its contents and then sending brief relevant information as the subject line of an email to be read on a mobile phone. The...
0
by: Manuel D. Jim?nez | last post by:
Hi, we are developing an ActiveX control which plays a video streaming. We have used Visual Studio .net wizard to develop almost all the control interface, however we have trouble with event...
3
by: weston | last post by:
I'm making a foray into trying to create custom vertical scrollbars and sliders, and thought I had a basic idea how to do it, but seem to be having some trouble with the implementation. My...
3
by: Hayden Kirk | last post by:
Hi, I'm trying to add databinding to the wizard control. Basically a user is entering their email address and I want to validate this to a sql database when the hit next but I cannot get this to...
3
by: Groove | last post by:
Hey guys - hoping you can help me out here. I'm using asp.net 2 (VB) and trying to set and retrieve values from a cookie. I've done this a few times before w/o a problem but I seem to be...
5
by: Amoril | last post by:
I've read quite a few different message on various boards and for some reason I'm still having trouble wrapping my head around this viewstate maintenance and trying to get these dynamically created...
1
by: Tableshavturned | last post by:
Hi this is my first post on the forums. I haven't really developed before with Access 2003 so trouble shooting with this application is not my forte. The issue at hand is, created a star schema with...
1
by: ced69 | last post by:
having trouble getting marquee to work get object required errors tring t <title>This Month at the Chamberlain Civic Center</title> <link href="styles.css" rel="stylesheet"...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.