Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #18163 > unrolled thread
| Started by | "Mel Smith" <med_cutout_syntel@aol.com> |
|---|---|
| First post | 2013-01-20 10:42 -0700 |
| Last post | 2013-01-23 13:49 -0800 |
| Articles | 18 — 5 participants |
Back to article view | Back to comp.lang.javascript
IE8 attachEvent problem "Mel Smith" <med_cutout_syntel@aol.com> - 2013-01-20 10:42 -0700
Re: IE8 attachEvent problem Martin Honnen <mahotrash@yahoo.de> - 2013-01-20 18:55 +0100
Re: IE8 attachEvent problem "Mel Smith" <med_cutout_syntel@aol.com> - 2013-01-20 10:59 -0700
Re: IE8 attachEvent problem "Mel Smith" <med_cutout_syntel@aol.com> - 2013-01-20 11:24 -0700
Re: IE8 attachEvent problem Martin Honnen <mahotrash@yahoo.de> - 2013-01-21 12:06 +0100
Re: IE8 attachEvent problem "Mel Smith" <med_cutout_syntel@aol.com> - 2013-01-21 09:52 -0700
Re: IE8 attachEvent problem "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-01-20 20:11 +0100
Re: IE8 attachEvent problem "Mel Smith" <med_cutout_syntel@aol.com> - 2013-01-20 13:21 -0700
Re: IE8 attachEvent problem Bjoern Hoehrmann <bjoern@hoehrmann.de> - 2013-01-20 21:44 +0100
Re: IE8 attachEvent problem "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-01-21 00:07 +0100
Re: IE8 attachEvent problem "Mel Smith" <med_cutout_syntel@aol.com> - 2013-01-20 16:19 -0700
Re: IE8 attachEvent problem "Mel Smith" <med_cutout_syntel@aol.com> - 2013-01-20 17:18 -0700
Re: IE8 attachEvent problem Martin Honnen <mahotrash@yahoo.de> - 2013-01-21 18:28 +0100
Re: IE8 attachEvent problem "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-01-21 19:07 +0100
Re: IE8 attachEvent problem Martin Honnen <mahotrash@yahoo.de> - 2013-01-21 19:33 +0100
Re: IE8 attachEvent problem "Mel Smith" <med_cutout_syntel@aol.com> - 2013-01-21 13:05 -0700
Re: IE8 attachEvent problem "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-01-22 09:00 +0100
Re: IE8 attachEvent problem Arty Effem <ignoring@mail.com> - 2013-01-23 13:49 -0800
| From | "Mel Smith" <med_cutout_syntel@aol.com> |
|---|---|
| Date | 2013-01-20 10:42 -0700 |
| Subject | IE8 attachEvent problem |
| Message-ID | <am2ojqFk54hU1@mid.individual.net> |
Hi:
Environment: As a client using an IE8 browser on a Win XP Pro (sp2) machine:
Within the javascript code in my page there is a 'function remember()'.
It is shown as --- the problem function --- below. The function 'remembers'
where in a long table my user was viewing, so that when he 'returns' to the
page, I position his viewport to the 'remembered' set of lines. It has
worked fine for a long time but under IE7. Recently, I have started using
IE8 as a testbed (in addition to Chrome and FF), and set IE8 to show me JS
errors when viewing pages.
When this remember function is called , IE8 shows a 'Type Mismatch'
error at character 4 of
the offending line (indicated by asterisks ("*****") below.
When viewed with Chrome and FF, there is no problem because these
browsers use addEventListener as the event handler (instead of attachEvent).
I'm not a newbie, just a stupie, and would like to continue using this
'remember' function without the error.
Hope that someone can help me fix this error on IE8
Thank you.
--
Mel Smith
Mesa, Arizona
------- the problem function ----------
function remember(e) {
var targ,tid;
if (!e)
{
var e=window.event;
}
if (e.target)
{
targ=e.target;
}
else if (e.srcElement)
{
targ=e.srcElement;
}
if (targ.nodeType==3) // defeat Safari bug
{
targ = targ.parentNode;
}
tid=targ.id;
if (window.addEventListener) {
window.addEventListener("load",document.getElementById(tid).scrollIntoView(),false)
;
}
else if (window.attachEvent) {
// ********** next line shows a 'Type Mismatch' error at char(4)
********
window.attachEvent("onload",document.getElementById(tid).scrollIntoView())
;
}
else {
alert("c. No adding or attaching") ;
window.onload = "document.getElementById(tid).scrollIntoView();"
}
return ;
}
--
Mel Smith
[toc] | [next] | [standalone]
| From | Martin Honnen <mahotrash@yahoo.de> |
|---|---|
| Date | 2013-01-20 18:55 +0100 |
| Message-ID | <50fc2fac$0$6566$9b4e6d93@newsspool4.arcor-online.net> |
| In reply to | #18163 |
Mel Smith wrote:
> function remember(e) {
> var targ,tid;
> if (!e)
> {
> var e=window.event;
> }
> if (e.target)
> {
> targ=e.target;
> }
> else if (e.srcElement)
> {
> targ=e.srcElement;
> }
> if (targ.nodeType==3) // defeat Safari bug
> {
> targ = targ.parentNode;
> }
> tid=targ.id;
>
> if (window.addEventListener) {
> window.addEventListener("load",document.getElementById(tid).scrollIntoView(),false)
> ;
> }
> else if (window.attachEvent) {
>
> // ********** next line shows a 'Type Mismatch' error at char(4)
> ********
> window.attachEvent("onload",document.getElementById(tid).scrollIntoView())
> ;
> }
> else {
> alert("c. No adding or attaching") ;
> window.onload = "document.getElementById(tid).scrollIntoView();"
> }
>
> return ;
> }
With both event APIs (MSHTML/IE as well as the W3C DOM) you need to pass
in a function object that you want to be called, not call a function. So
you need
window.addEventListener("load"
function() {
document.getElementById(tid).scrollIntoView();
},
false
);
respectively
window.attachEvent("onload", function() {
document.getElementById(tid).scrollIntoView(); });
On the other hand if your remember function is called onload then it
should suffice to simply call the scrollIntoView, as your current code
does anyway, only accidentally.
So depending on when/where you execute the remember function, you might
not need to use addEventListener respectively attachEvent, you can
simply put your
document.getElementById(tid).scrollIntoView();
in the remember function.
[toc] | [prev] | [next] | [standalone]
| From | "Mel Smith" <med_cutout_syntel@aol.com> |
|---|---|
| Date | 2013-01-20 10:59 -0700 |
| Message-ID | <am2pjiFkcl1U1@mid.individual.net> |
| In reply to | #18164 |
Martin said:
>
> With both event APIs (MSHTML/IE as well as the W3C DOM) you need to pass
> in a function object that you want to be called, not call a function. So
> you need
> window.addEventListener("load"
> function() {
> document.getElementById(tid).scrollIntoView();
> },
> false
> );
> respectively
> window.attachEvent("onload", function() {
> document.getElementById(tid).scrollIntoView(); });
>
> On the other hand if your remember function is called onload then it
> should suffice to simply call the scrollIntoView, as your current code
> does anyway, only accidentally.
>
> So depending on when/where you execute the remember function, you might
> not need to use addEventListener respectively attachEvent, you can simply
> put your
> document.getElementById(tid).scrollIntoView();
> in the remember function.
>
Hi Martin:
I'll print and study your response.
Thank you !
-Mel Smith
[toc] | [prev] | [next] | [standalone]
| From | "Mel Smith" <med_cutout_syntel@aol.com> |
|---|---|
| Date | 2013-01-20 11:24 -0700 |
| Message-ID | <am2r29Fko0fU1@mid.individual.net> |
| In reply to | #18165 |
Hi Martin:
Below is how the 'remember' function is currently called:
There are approx 150 buttons on the page. When *any* button is clicked,
I 'submit' the form and a new page is sent to the browser. When the user
'backs up', then I expect the previous page to be displayed in the viewport
at the appropriate set of lines which were 'remembered'.
It *does this* but still shows the error on IE8.
Thanks,
-Mel
----- remember() is *only* 'called' here --------
<form id="someid" name="frmmenu" action="/cgi-bin/xxx/myscript.exe"
method="post" onclick="remember(event);">
------------------------------------------------
[toc] | [prev] | [next] | [standalone]
| From | Martin Honnen <mahotrash@yahoo.de> |
|---|---|
| Date | 2013-01-21 12:06 +0100 |
| Message-ID | <50fd2118$0$6563$9b4e6d93@newsspool4.arcor-online.net> |
| In reply to | #18166 |
Mel Smith wrote:
> It *does this* but still shows the error on IE8.
I am not sure about older IE versions, according to
http://msdn.microsoft.com/en-us/library/ie/ms536730%28v=vs.85%29.aspx
scrollIntoView takes a boolean argument.
Does the error vanish when you explicitly call
document.getElementById(tid).scrollIntoView(true);
? Or which statement currently gives the error?
[toc] | [prev] | [next] | [standalone]
| From | "Mel Smith" <med_cutout_syntel@aol.com> |
|---|---|
| Date | 2013-01-21 09:52 -0700 |
| Message-ID | <am5a2tF758fU1@mid.individual.net> |
| In reply to | #18187 |
Martin said:
"Martin Honnen" <mahotrash@yahoo.de> wrote in message
news:50fd2118$0$6563$9b4e6d93@newsspool4.arcor-online.net...
> Mel Smith wrote:
>
>> It *does this* but still shows the error on IE8.
>
>
> I am not sure about older IE versions, according to
> http://msdn.microsoft.com/en-us/library/ie/ms536730%28v=vs.85%29.aspx
> scrollIntoView takes a boolean argument.
> Does the error vanish when you explicitly call
> document.getElementById(tid).scrollIntoView(true);
> ? Or which statement currently gives the error?
>
Hi Martin:
In a 'later/lower' post, I corrected statement in question and used
'document.body. etcetera' . This stopped the error.
With that correction, I now have the following results:
IE8 - Works corectly
FF - Works correctly
Opera - Works correctly
Chrome - Page displays at *top*, not where it was 'remembered'
Safari - Page displays at *top*, not where it was 'remembered'
Since my users are older retired north americans, and since in this
demographic (IE and Chrome) are predominant, I'd like to determine why
Chrome is not scrolling to the remembered position (which is a multi-line
cell in a long 3-column table)
btw, I *did* place a 'true' as an argument in the scrollIntoView()
function. But, this is the default anyway and made no difference.
Also, I placed an Alert() just ahead of the 'scroll' code to ensure that
the ID was correct. It _was_
So, if I change the 'onload' event to point at my new ID, why is it
ignored by Chrome and Safari when I 'return' to the page ??
Thanks for the comment.
-Mel Smith
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2013-01-20 20:11 +0100 |
| Message-ID | <XnsA14ECD702F2eejj99@194.109.133.133> |
| In reply to | #18163 |
Mel Smith wrote on 20 jan 2013 in comp.lang.javascript: > window.onload = "document.getElementById(tid).scrollIntoView();" If you change this to: body.onload = 'document.getElementById(tid).scrollIntoView();' ... shouldn't it work on most browsers, "eventually" not needing any other "attaching"? -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | "Mel Smith" <med_cutout_syntel@aol.com> |
|---|---|
| Date | 2013-01-20 13:21 -0700 |
| Message-ID | <am31v9Fmcu4U1@mid.individual.net> |
| In reply to | #18167 |
Evertjan said:
>> window.onload = "document.getElementById(tid).scrollIntoView();"
>
> If you change this to:
>
> body.onload = 'document.getElementById(tid).scrollIntoView();'
>
> ... shouldn't it work on most browsers,
> "eventually" not needing any other "attaching"?
>
Hi Evertjan:
I've changed my remember() function to what is show below, and
re-tested:
Result:
On IE8, I get the error 'body is undefined'
BUT, it works on IE8 and I return to the 'remembered' set of lines in
the table even with the 'indefined' error ???
On Chrome, FF, ands Safari, I'm not sure what is going on ...
-Mel
--------------------------
function remember(e) {
var targ,tid;
if (!e)
{
var e=window.event;
}
if (e.target)
{
targ=e.target;
}
else if (e.srcElement)
{
targ=e.srcElement;
}
if (targ.nodeType==3) // defeat Safari bug
{
targ = targ.parentNode;
}
tid=targ.id;
body.onload="document.getElementById(tid).scrollIntoView();"
return;
}
[toc] | [prev] | [next] | [standalone]
| From | Bjoern Hoehrmann <bjoern@hoehrmann.de> |
|---|---|
| Date | 2013-01-20 21:44 +0100 |
| Message-ID | <6nlof8pgvu18gr4a6ctul5081r2qkr5p78@hive.bjoern.hoehrmann.de> |
| In reply to | #18168 |
* Mel Smith wrote in comp.lang.javascript: > On IE8, I get the error 'body is undefined' >body.onload="document.getElementById(tid).scrollIntoView();" You are probably looking for `document.body`. -- Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de Am Badedeich 7 · Telefon: +49(0)160/4415681 · http://www.bjoernsworld.de 25899 Dagebüll · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2013-01-21 00:07 +0100 |
| Message-ID | <XnsA14F13653D5Feejj99@194.109.133.133> |
| In reply to | #18169 |
Bjoern Hoehrmann wrote on 20 jan 2013 in comp.lang.javascript: > * Mel Smith wrote in comp.lang.javascript: >> On IE8, I get the error 'body is undefined' > >>body.onload="document.getElementById(tid).scrollIntoView();" > > You are probably looking for `document.body`. Right. However the above still cannot be working in a function that is executed after the page is ready, as the unload executes as the last part of the loading process. I suppose the OP wants the page to store somewhere the position of the page shown, and retrieved in a next invocation of that same page later. The document.body.onload='' or the <body onload='..'> should work on that next page if executed during the loading. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | "Mel Smith" <med_cutout_syntel@aol.com> |
|---|---|
| Date | 2013-01-20 16:19 -0700 |
| Message-ID | <am3cc5Foo7aU1@mid.individual.net> |
| In reply to | #18169 |
Bjoern said:
>* Mel Smith wrote in comp.lang.javascript:
>> On IE8, I get the error 'body is undefined'
>
>>body.onload="document.getElementById(tid).scrollIntoView();"
>
> You are probably looking for `document.body`.
Hi Bjoern:
After taking a little nap, I awoke with a light-bulb bubble over my head
which was, of course, which you noted above.
-Mel
[toc] | [prev] | [next] | [standalone]
| From | "Mel Smith" <med_cutout_syntel@aol.com> |
|---|---|
| Date | 2013-01-20 17:18 -0700 |
| Message-ID | <am3friFpeoaU1@mid.individual.net> |
| In reply to | #18175 |
Bjoern, Martin and Evertjan:
>>>body.onload="document.getElementById(tid).scrollIntoView();"
>>
>> You are probably looking for `document.body`.
Hi:
The statement:
document.body.onload="document.getElementById(tid).scrollIntoView();"
... works perfectly for IE8 and Safari
For Chrome, the original page displays at the top and not where the
viewer left it.
I'll do more testing.
Thanks to y'all !
-Mel Smith
[toc] | [prev] | [next] | [standalone]
| From | Martin Honnen <mahotrash@yahoo.de> |
|---|---|
| Date | 2013-01-21 18:28 +0100 |
| Message-ID | <50fd7ab9$0$6562$9b4e6d93@newsspool4.arcor-online.net> |
| In reply to | #18167 |
Evertjan. wrote: > Mel Smith wrote on 20 jan 2013 in comp.lang.javascript: > >> window.onload = "document.getElementById(tid).scrollIntoView();" > > If you change this to: > > body.onload = 'document.getElementById(tid).scrollIntoView();' > > ... shouldn't it work on most browsers, > "eventually" not needing any other "attaching"? I am confused, which browsers support assigning a string with Javascript code as an event handler to the DOM property reflecting an attribute? Wouldn't you need to assign a function?
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2013-01-21 19:07 +0100 |
| Message-ID | <XnsA14FC2A1E151Ceejj99@194.109.133.133> |
| In reply to | #18190 |
Martin Honnen wrote on 21 jan 2013 in comp.lang.javascript:
> Evertjan. wrote:
>> Mel Smith wrote on 20 jan 2013 in comp.lang.javascript:
>>
>>> window.onload = "document.getElementById(tid).scrollIntoView();"
>>
>> If you change this to:
>>
>> body.onload = 'document.getElementById(tid).scrollIntoView();'
>>
>> ... shouldn't it work on most browsers,
>> "eventually" not needing any other "attaching"?
>
> I am confused, which browsers support assigning a string with Javascript
> code as an event handler to the DOM property reflecting an attribute?
> Wouldn't you need to assign a function?
Your testing is as good as my testing, I suppose.
Methinks both should do fine, you test it:
================
document.body.onload = 'alert("I`m loaded");'
================
and
================
function sureIam() {
alert("I`m loaded");
};
document.body.onload = sureIam;
================
Mind: no () in the latter.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | Martin Honnen <mahotrash@yahoo.de> |
|---|---|
| Date | 2013-01-21 19:33 +0100 |
| Message-ID | <50fd89de$0$6555$9b4e6d93@newsspool4.arcor-online.net> |
| In reply to | #18191 |
Evertjan. wrote:
> Martin Honnen wrote on 21 jan 2013 in comp.lang.javascript:
>
>> Evertjan. wrote:
>>> If you change this to:
>>>
>>> body.onload = 'document.getElementById(tid).scrollIntoView();'
>>>
>>> ... shouldn't it work on most browsers,
>>> "eventually" not needing any other "attaching"?
>>
>> I am confused, which browsers support assigning a string with Javascript
>> code as an event handler to the DOM property reflecting an attribute?
>> Wouldn't you need to assign a function?
>
> Your testing is as good as my testing, I suppose.
>
> Methinks both should do fine, you test it:
>
> ================
> document.body.onload = 'alert("I`m loaded");'
I don't see why assigning a string would do, it doesn't work for me
(http://jsfiddle.net/kF8se/). Tested with current versions of FF, IE,
Chrome, Opera on Windows 8.
Assigning a function is different (http://jsfiddle.net/t6JVX/1/), works
fine with above named browsers.
What you could do is use setAttribute (http://jsfiddle.net/TEE8c/1/) if
you really want to work with a string but I wouldn't recommend that due
to the way setAttribute works with older IE versions.
[toc] | [prev] | [next] | [standalone]
| From | "Mel Smith" <med_cutout_syntel@aol.com> |
|---|---|
| Date | 2013-01-21 13:05 -0700 |
| Message-ID | <am5ld5F9r3hU1@mid.individual.net> |
| In reply to | #18191 |
Evertjan said:
> Methinks both should do fine, you test it:
>
> ================
> document.body.onload = 'alert("I`m loaded");'
> ================
>
> and
>
> ================
> function sureIam() {
> alert("I`m loaded");
> };
>
> document.body.onload = sureIam;
> ================
>
> Mind: no () in the latter.
Hi Evertjan:
How do I change my 'remember' code to make it an 'onload function call'
and pass it the target and ID -- instead of a string. I'm getting more and
more confused here :(.
Thank you
-Mel
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2013-01-22 09:00 +0100 |
| Message-ID | <XnsA1505BAA5346Ceejj99@194.109.133.133> |
| In reply to | #18193 |
Mel Smith wrote on 21 jan 2013 in comp.lang.javascript: > Evertjan said: >> document.body.onload = sureIam; >> ================ >> >> Mind: no () in the latter. > How do I change my 'remember' code to make it an 'onload function > call' > and pass it the target and ID -- instead of a string. I'm getting > more and more confused here :(. Sorry, I only tried to address the onload issue. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | Arty Effem <ignoring@mail.com> |
|---|---|
| Date | 2013-01-23 13:49 -0800 |
| Message-ID | <a79f8df0-c782-405e-99fe-608634de5f5d@googlegroups.com> |
| In reply to | #18163 |
On Sunday, 20 January 2013 17:42:14 UTC, Mel Smith wrote:
> Hi:
>
>
>
> Environment: As a client using an IE8 browser on a Win XP Pro (sp2) machine:
>
>
>
> Within the javascript code in my page there is a 'function remember()'.
>
> It is shown as --- the problem function --- below. The function 'remembers'
>
> where in a long table my user was viewing, so that when he 'returns' to the
>
> page, I position his viewport to the 'remembered' set of lines. It has
>
> worked fine for a long time but under IE7.
That function has never worked, it just looked as though it did.
attachEvent/addeventLister expect a function reference and that's not what you're passing them. You are executing scrollIntoView immediately, without waiting for load.
window.addEventListener("load", function(){ document.getElementById(tid).scrollIntoView(); } ,false);
etc. It would be better to define the function separately and just pass its name ( without () ) in the three places in the code.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web