I have an application where the user loads graphics from another site.
Presently I advise the user to wait for graphics to load before
clicking on adjustments. Ideally, I would prefer a closed-loop approach
where code would recognize completion of loading and automatically
enable the adjustments. Any ideas on how I can tap into what my browser
knows would be appreciated.
Jan 5 '06
13 1695
Thomas 'PointedEars' Lahn wrote: [0] Therefore, an attempt at improving its efficiency and reliability:
function _addEventListen er(o, sEvent, fListener, bUseCapture) { var result = false;
if (o && sEvent && isMethodType(ty peof fListener)) { if (isMethodType(t ypeof o.addEventListe ner)
^ {
Tried and failed :)
Thomas 'PointedEars' Lahn wrote: a1*****@aol.com wrote:
Thomas 'PointedEars' Lahn wrote: [...] Use the `onload' event handler of the `body' element. Quickhack:
<head> ... <meta http-equiv="Content-Script-Type" content="text/javascript"> ... <script type="text/javascript"> function isMethodType(s) { return (s == "function" || s == "object"); }
function _addEventListen er(o, sEvent, fListener, bUseCapture) { if (o) { if (isMethodType(t ypeof o.addEventListe ner) && isMethodType(ty peof fListener)) { o.addEventListe ner(sEvent, fListener, !!bUseCapture); result = true; } else if (isMethodType(t ypeof o.attachEvent) && isMethodType(ty peof fListener)) { result = o.attachEvent(" on" + sEvent, fListener); } else { o["on" + sEvent] = fListener; result = (o["on" + sEvent] == fListener); } } }
function addEventListene rToImg(sName, sEvent, fListener, bUseCapture) { var img; if (typeof document != "undefined" && document.images && (img = document.images[sName])) { return _addEventListen er(img, sEvent, fListener, bUseCapture); }
return false; }
function bar() { // ... } </script> ... </head>
<body ... onload="addEven tListenerToImg( 'foo', 'load', bar);"> ... <img ... name="foo"> ... </body> [...]
Please trim your quotes to the minimum required for retaining the context.
<URL:http://jibbering.com/faq/faq_notes/pots1.html#ps1P ost>
I thank you for the code. It works fine for IE 6.0 and when I figure out how it works
Why, you could ask its author ...
Since you have asked, I will take the liberty of asking a dump
question.
Why does the browser allow a call of addEventListene rToImg with three
parameters when the called function specifies four variables?
BTW, your typo did not cause any problems and the modified code worked
on Internet Explorer and only on the initial download with Opera. Since
IE intrinsically supports an onload event in the img tag, the routine
adds little to my page so I decided not to use it.
I would be interested to learn more about html validation and where can
I obtain a validation program of offline use.
Herbert It is fairly simple: when the `load' event of the `body' element fires, the `img' element named "foo" is added an event listener for its `load' event, where several approaches to do so are feature-tested and the first positive tested feature is used[0]. That event listener, `bar', is called when the `img' element's `load' event fires.
[0] Therefore, an attempt at improving its efficiency and reliability:
function _addEventListen er(o, sEvent, fListener, bUseCapture) { var result = false;
if (o && sEvent && isMethodType(ty peof fListener)) { if (isMethodType(t ypeof o.addEventListe ner) { o.addEventListe ner(sEvent, fListener, !!bUseCapture); result = true; } else { if (isMethodType(t ypeof o.attachEvent)) { result = o.attachEvent(" on" + sEvent, fListener); }
if (!result) { o["on" + sEvent] = fListener; result = (o["on" + sEvent] == fListener); } } }
return result; }
Note that the feature test for addEventListene r() is still not sufficient as it only tests for existence, not functionality. If someone could come up with a reliable method to determine if addEventListene r() was successful (since it does not have a return value or exception specified), that would make this approach less error-prone.
then perhaps I could get the code to work with my Opera and Netscape browsers.
And what exactly does not work there?
The code does work with Netscape (presumably 2.0+[1], tested with [2], [3] and [4]), and Opera[5]. (However, it should be noted that in Netscape 4.8 and animated GIFs, the `onload' handler is triggered there every time the animation loops.) Opera even supports elemObjRef.addE ventListener('l oad', ...) for HTMLImageElemen t objects referred to by `elemObjRef', although there is no such event for `img' elements according to W3C DOM Level 2 Events 1.0; ISTM it is implementing W3C WG Note W3C DOM Level 3 Events 1.0 here, where the event applies to such elements, being "a resource linked from the document."[6]
What you may encounter, of course, is that bar() will not be called on creation of the `img' element if the `load' event of the `img' element fired before the `load' event of the `body' element fires. The above approach works quite reliably only if you want to handle `src' attribute changes to the `img' element after it was first loaded.
I am not sure if there is always a viable workaround for that. A possible workaround without invalid HTML would probably be to try to add the event listener for the `load' event of the `img' element right after if was included or at the end of the document's body element.
A possible workaround with Valid XHTML could be to augment the XHTML DTD with the `onload' attribute for the `img' element, such as
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d" [ <!ATTLIST img onload CDATA #IMPLIED > ]>
I have tested the former successfully in Netscape 4.8+, Firefox 1.5 and Opera 8.51, and the latter (XHTML) successfully in Netscape 6.2.3+ (see footnotes) and Firefox 1.5 using Gecko's XML parser (by serving application/xhtml+xml).
What was most interesting to me when pursuing the latter approach is that XML 1.0, which is used to define XHTML 1.0, explicitly allows the latter[7], so it is indeed Valid markup and does not break the DTD declaration. And there is also a disturbing fact: Even though the XHTML 1.0 Transitional DTD does not declare the `onload' attribute for the `img' element, Gecko's XML parser in Standards Compliance Mode does not find anything not well-formed with the markup when I omit the above ATTLIST declaration; the W3C Markup Validator does.
Of course, a possible workaround with invalid HTML is to use the `onload' attribute of the `img' element anyway, but I recommend against that.
HTH
PointedEars ___________ [1] <URL:http://research.nihons oft.org/javascript/jsref/doc1.htm#101084 2> [2] Mozilla/4.8 [en] (X11; U; Linux 2.6.14.4-20051220.153223 +0100 i686) [3] Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.4.1) Gecko/20020508 Netscape6/6.2.3 [4] Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.2) Gecko/20040805 Netscape/7.2 [5] Opera/8.51 (X11; Linux i686; U; en) [6] <URL:http://www.w3.org/TR/DOM-Level-3-Events/events.html#Eve nts-eventgroupings-htmlevents> [7] <URL:http://www.w3.org/TR/REC-xml/#NT-doctypedecl> <URL:http://www.w3.org/TR/REC-xml/#NT-AttlistDecl> "When more than one AttlistDecl is provided for a given element type, the contents of all those provided are merged." a1*****@aol.com wrote: Thomas 'PointedEars' Lahn wrote: a1*****@aol.com wrote:
Please trim your quotes to the minimum required for retaining the context.
<URL:http://jibbering.com/faq/faq_notes/pots1.html#ps1P ost>
See also the bottom of this posting. > I thank you for the code. It works fine for IE 6.0 and when I figure > out how it works Why, you could ask its author ...
Since you have asked, I will take the liberty of asking a dump question.
Why does the browser allow a call of addEventListene rToImg with three parameters when the called function specifies four variables?
Because in JS/ECMAScript, functions have no fixed arity (and so allow for
trailing optional arguments without additional declaration). Arguments,
including named arguments, that are not passed, are assigned the value
`undefined', and unnamed arguments can be accessed within the method via
`arguments', which refers to an Array-like object.
BTW, your typo did not cause any problems
Impossible. Probably the syntax error was not displayed, but it was there.
<URL:http://jibbering.com/faq/#FAQ4_43>
and the modified code worked on Internet Explorer
OK
and only on the initial download with Opera.
Pardon?
Since IE intrinsically supports an onload event in the img tag,
Still it is not Valid markup and therefore not only the markup is
error-prone but also the scripts that are operating on it. What IE
supports is not a standard you can build interoperable documents on.
To put it bluntly: IEeek can make gold out of every piece of sh*t.
the routine adds little to my page so I decided not to use it.
And you will have to live with that decision.
I would be interested to learn more about html validation and where can I obtain a validation program of offline use.
HTML Tidy is a validation and/or markup clean-up tool, EclipseTidy is
the respective Eclipse plugin which I use. MyEclipse's HTML Editor
also includes a simple markup validator for HTML, and XML applications.
If you meant instead that you want to validate documents without
uploading them your Web site first, use the Validator's File Upload
feature.
[Full quote]
Do that again and you will be killfiled. You have been warned.
PointedEars
Thomas 'PointedEars' Lahn wrote: [...] MyEclipse's HTML Editor also includes a simple markup validator for HTML, and XML applications.
Should have been:
MyEclipse also includes a simple markup validator for HTML (in the
HTML editor plugins), and XML applications (in the XML editor plugin).
PointedEars This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: IGC |
last post by:
I have a requirement to record in a database when a file is finished
downloading to the end-user. Currently when a user clicks a download icon
for a file it directs to an ASP page that records the "hit" into a database,
then I use a response.redirect "filename.exe" to point the user to the
download. What I'm missing is knowing when the download is complete so I
can update the database to show the file successfully completed its
download....
|
by: Brian Cryer |
last post by:
I'm working on a VB.NET project where we are intending to use MSDE as our
back-end database. The actual number of users is expected to be low and I
don't have any concerns as to whether MSDE will be up to the job (most of
the time). I'm aware that if we end up with lots of users connecting to our
site at once (which may happen as certain times in the year when people need
information for deadlines) then the performance governor in MSDE will...
|
by: Bill S. |
last post by:
Hey, I am trying to figure this out. The hyperlinks on my page open
up a small popup window. I have no reason to refresh the parent page
or what have you. I was living in a very happy world, with no
problems or disturbances. However, a problem has since arisen: The
search engines have indexed these popup pages. So, you load them, but
there are no links on them, and there is no parent page. Many people
would not check out the url and...
|
by: Greg Lindstrom |
last post by:
I have an odd problem that I'm sure someone here can help me solve. I
am using Python 2.3 on a Linux box to process text files. At one point
in my automated process, I have to zip and ship the files over to a
Windows server running a proprietary package to do some manipulation to
the file. Problem is that I need to know when the process completes
processing the file. Complicating matters is that this package names
the output file using...
|
by: Niklas Ringdahl |
last post by:
Hello.
I am using databindings to bind my dataset to comboboxes, textboxes and
labels. Some of my UI depends on knowing when the user changes the values,
but I have some problems knowing when my dataset value is set in the
controls.
- SelectedIndexChanged event fires during the bind process, so I can't just
use that
- The binding don't seem to "kick in" until the tab page where the control
| |
by: Greg |
last post by:
Is there a way I can find out if a file is in use or not? My app is calling
an external converter and doesn't wait for it to finish (would like it to,
but doesn't appear that it can). The problem is, it never knows when the
file the external converter writes to is finished. I've tried a few things,
including waiting for the file attributes to become FileAttributes.Normal
(which it never becomes). The file attribute is always...
|
by: chad |
last post by:
let's say I'm transferring a large file like 100MB over to a folder.
The program detects when the file arrives. However, I can't
figure out how to know when the file is totally transferred over.
One unsuccessful method is to...
dim fi as new fileinfo(newfile)
fi.length returns the supposed size of the file. But it correctly
|
by: GoogleNewsReaderMan |
last post by:
Is there a way for me to know from within a given assembly when it gets
loaded? If so, how can this be done?
Thanks in advance!
|
by: jaim |
last post by:
In my web page there is a text 2nd number of your passcode when the page loaded , dynamicaaly each time number is getting changed. And also having the Combo box to select the values (0-9) this should match the text in the label.
Is there any way to get the number in the text which is changing dynamically and parametrise the combox box values to match exactly same as labels
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |