Re: Causing File Download on Page Load



'PointedEars',

I very much appreciate the additional details.

For example, I'm not sure I understand the difference between putting code
in the onload event or just sticking it in the body (as ASP.NET will do when
I register a start-up script),

Script code in the `onload' event-handler attribute value of the BODY
element (or in another event listener for the `load' event of the
corresponding DOM object) will be executed when the document has been loaded.

Script code in the document head or body is executed while the document is
being loaded.

So script in the onload handler executes after the document is finished loading? And you prefer that approach because it ensures my script does not somehow prevent the document from loading completely? Makes good sense to me!

I have no idea what is meant in the TODO comment about using a wrapper,

on* properties are proprietary (non-standard). For an approach that targets
maximum possible compatibility (one that is "cross-browser"), a wrapper
method is necessary that prefers the standard-compliant methods
addEventListener() and removeEventListener() over assigning a Function
object reference or `null' to those properties, respectively.

<http://msdn.microsoft.com/en-us/library/ms536973(VS.85).aspx>

Okay. (Didn't see anything at that link about event listeners though.)

Such a wrapper method uses feature detection to determine if either method
is probably callable (using the user-defined isMethod() method above). If
yes, it calls them; if no, it makes the assignment instead.

If isMethod is a user-defined method, I haven't seen the definition for it. (Perhaps you meant predefined?)

However, in this case the event listeners have been specified in the markup
and not using a wrapper. Therefore, no Function object reference would be
available for passing it to EventTarget::removeEventListener(). And one
might need to rely on that the proprietary properties are supported because
AFAIK they cannot be reliably feature-tested and so a wrapper method would
not be of much use *here*. Sorry for causing confusion.

So, does this mean you would just leave that part of your original code as is? (Which simply assigns null to onload and onunload?)

And may I ask the main reason for removing the handlers for these events in download.action? I know you don't want to trigger a second download, but I'm not sure I see where that could happen. And a page refresh would just reset them again anyway, right?

Nevertheless, if we assumed that the event listeners would have been added
using script instead --

[...]

I understand that you are battling here with issues of browser compatibility and I've printed out your post. But it's pretty rough reading for me at this stage. Are you just providing this as complete information, or do you think it should be incorporated into what I'm doing here?

(It would appear there was not sufficient reason to remove
_removeEventListener() from dhtml.js, if it was there before.)

and I just don't know the intent of most statements in the code.

You can ask about them, of course, and I'll do my best to explain, but you
need to make an effort in learning -- that is, *self-study* -- in order to
accomplish anything here.

Sure, and sorry if I sometimes seem impatient. The fact is that I'm a bit overloaded here. My background is with non-Web development and over the past year or two have been learning .NET, ASP.NET, C#, HTML, CSS, SQL and I guess I should add javascript to that list. And, now, I'm under an extremely heavy workload. So it should be understandable that I get a little frustrated when some things come a little harder than it seems they should.

But I do apprecate your time in fleshing out some of the details for me. I am making an effort but this discussion has opened my eyes to a few things.

(BTW, it's come to my attention that some shareware sites use iframe tags to perform this task: <iframe style="display:none;" height="0" width="0" src="url"></iframe> Of course, that approach has it's own issues dealing with browser differences.)

Thanks!

Jonathan

.



Relevant Pages

  • Re: John Resig Video
    ... that it should only be used on script resources where it ... That fulfills the "doesn't matter when it executes" statement. ... And in environments were defer is not implemented that same script is going to processed inline and so be executed before the DOM is complete, which could still happen even if defer is implemented as "can continue ...
    (comp.lang.javascript)
  • Files appear to be cross linked
    ... script requires a number of standard environment variables to be set ... so it calls a second shell script to set these at the session level, ... control should return to the first shell script, ... that the script executes to the last line prior to the displaying of ...
    (comp.unix.solaris)
  • Re: Dynamic select lists using optgroups again - without frameworks
    ... in the last script element. ... The DOM will be ready and you don't need to use window.onload (or ... Using onload is also based on the "mere assumption" that the UA ... at the time the feature was introduced, ...
    (comp.lang.javascript)
  • Re: (non-root) setuid and permissions
    ... >>To summarize, the script can't be readable by the user, but it must ... Convince someone in power to allow you to run the wrapper program ... the wrapper could then execute your ... If the wrapper program is set-userid root, and it executes the script, ...
    (comp.unix.programmer)
  • Re: Build web apps in Javascript - new service open for beta
    ... You are using the onload event of two entirely different ... was attempting to add an event handler to a single element. ... means do it by script. ... Your "senior programmer" should be demoted to junior ...
    (comp.lang.javascript)