I think you're misinterpreting why the change was made. This is for the case
where the script removes itself (not when the onload/onreadystatechange is
called more than once). In general, it's just good practice to make sure
that the element does exist, anyway.

--John


On Mon, Jul 27, 2009 at 12:36 PM, Andrea Giammarchi <
andrea.giammar...@gmail.com> wrote:

> John there is something wrong here. First of all it is not possible that
> that function is called twice in a call because that "done" variable is not
> ambiguous at all.
>
> Secondly I do not think that onload should be messed up with
> onreadystatechange.
>
> onload is the only event we would use except some browser which does not
> fire it as expected.
>
> In these browsers a readyState check makes sense only inside an
> onreadystatechange event.
>
> If the script has not a parent anymore and that operation is performed
> twice I bet there is something wrong in the included script. It is probably
> modifying the DOM and scripts elements, that is why there is a problem.
>
> If that script for some reason has been moved or adopted the
> head.removeChild(script) will fail because the script will have a parentNode
> but it is not necessary that head.
>
> This is possible only because that operation is performed after
> success/complete and as soon as the script is evaluated by the browser. I
> wonder if this piece of code could solve every current or future problem
> with that step:
>
>             // Handle Script loading
>             if ( !jsonp ) {
>                 var onload = script.onload = function(){
>                         onload = script.onload = script.onreadystatechange
> = null;
>                         success();
>                         complete();
>                         if(script.parentNode)
>                             script.parentNode.removeChild(script);
>                     }
>                 ;
>                 script.onreadystatechange = function(){
>                     // this is an onreadystatechange problem, not an onload
> one
>                     if(/^(loaded|complete)$/.test(this.readyState))
>                         onload();
>                 };
>             }
>
>
> The onload variable is because in some browser ( not sure it is only with
> iframes ) you cannot call el.onload directly.
>
> Let me know what you think.
> Regards
>
>
>
>
> On Wed, Jul 22, 2009 at 3:48 PM, John Resig <jere...@gmail.com> wrote:
>
>> It's an easy enough change. I filed a bug and fixed it:
>> http://dev.jquery.com/ticket/4934
>>
>> --John
>>
>>
>>
>> On Tue, Jul 21, 2009 at 12:38 PM, vickyb <vicky.ble...@gmail.com> wrote:
>>
>>>
>>> Hello,
>>>
>>> I should start by saying I am fairly new to JQuery so please bear with
>>> me, but I would like to share a scenario with you all in the hope
>>> someone can offer some clarity.
>>>
>>> In this example, a user requests an external JavaScript file using
>>> jquery GET:
>>>
>>>
>>> -------------------------------------------------------------------------------------//
>>> START
>>>
>>>   $.ajax({ type: "GET", url: "***URL here***",
>>>
>>>
>>> -------------------------------------------------------------------------------------//
>>> END
>>>
>>> The requested JavaScript file performs several dynamic scripting
>>> functions (adding script elements to the document head) and then
>>> deletes itself purely to clean up the page source:
>>>
>>>
>>> -------------------------------------------------------------------------------------//
>>> START
>>>
>>>   //Locate the current script node
>>>   var scripts = document.getElementsByTagName('script');
>>>
>>>   var currentScript = scripts[scripts.length - 1];
>>>
>>>   //Set an id of the current script node if null
>>>   currentScript.id = ((currentScript.id.length == 0 ) ?
>>> "scriptToDelete" : currentScript.id );
>>>
>>>  //***REST OF CODE HERE
>>>   document.getElementById(currentScript.id).parentNode.removeChild
>>> (document.getElementById(currentScript.id));
>>>
>>>
>>> -------------------------------------------------------------------------------------//
>>> END
>>>
>>> In the event this file is called directly within a page (<script
>>> src=""></script>) the DOM tree is manipulated effectively and the
>>> 'currentScript' node is deleted. However in this example, due to
>>> maintenance code also in the JQuery library (below) this script node
>>> is deleted twice resulting in the 'Node not found error':
>>>
>>>   line 3494   // Handle memory leak in IE
>>>   line 3495   script.onload = script.onreadystatechange = null;
>>>   line 3496   head.removeChild( script ); ***conflicting code
>>>
>>> As the method of calling this external file isn't guaranteed (and thus
>>> it would be beneficial to leave this maintenance code in the external
>>> file), is it fair to assume both files (the external JS file, and the
>>> JQuery library) should perform a last minute check of 'does the parent
>>> node have this child node' before attempting this deletion?
>>>
>>> Or have I missed something?
>>>
>>> I look forward to your responses!
>>>
>>> Thanks.
>>>
>>>
>>>
>>
>>
>>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to