Bug Tracker

Modify

Ticket #3105 (closed bug: wontfix)

Opened 5 years ago

Last modified 23 months ago

<script> elments executed twice, once when document is "ready", and again when domManip gets called Options

Reported by: conor.moran Owned by: john
Priority: high Milestone: 1.next
Component: manipulation Version: 1.4.4
Keywords: document ready script execution needsreview Cc: scott.gonzalez@…
Blocking: Blocked by:

Description (last modified by jitter) (diff)

I have a pice of javascript that is on a page to bind an event handler to a button, somthing like:

<script type="text/javascript" charset="utf-8"> 
   $(document).ready( 
      function() { 
         $("#cancelpopup").click( 
            function(event) { 
               $('#eventId')[0].value='cancelpopup'; 
               $('#xform').submit(); 
            } 
         ); 
      } 
   ); 
</script> 

It uses jqModal plugin, which calls domManip in this case. domManip seems to have code in it to execute each <script> element, which seems to cause the click event handler to get bound a second time. (It was already bound after the page loaded initially)

This means my form gets submitted twice when I click the button.

It seems that the double binding of the click event is a bug.

I came across this issue elsewhere where another function called domManip so it is nothing to do with the jqModal plugin.

I'm using JQuery 1.2.6 in IE7.


Extra Info:

I'd emailed a query on this and John Resig responded:


I have an idea as to how this can be fixed (inline script tags would need to be marked, or removed, from the page as they're encountered). We do this to a lesser degree right now - but obviously we would need to step this up.

Could you file a ticket on this matter, in the bug tracker? Thank you.  http://dev.jquery.com/

--John

Attachments

test-3105.html Download (1.3 KB) - added by dmethvin 4 years ago.
Test case for #3105

Change History

comment:1 Changed 4 years ago by dmethvin

It's possible this is the cause of #3707 as well.

Changed 4 years ago by dmethvin

Test case for #3105

comment:2 Changed 4 years ago by dmethvin

  • Owner set to john

1.3b1 fixed this to some extent, but it reappeared in 1.3b2. jQuery.clean probably needs to execute scripts only if they come in as a string. DOM elements presumably have already been executed if they come from the document. New test case attached.

comment:3 Changed 4 years ago by john

So I implemented this in 1.3b1 - but doing so breaks other code more seriously (namely that $("<script>...</script>").appendTo("body"); now fails - and thus I had to roll it back for 1.3b2). Not a whole lot that we can do on our end, unfortunately.

comment:4 Changed 4 years ago by dmethvin

Closed duplicate #2226 and pointed it to here.

comment:5 Changed 4 years ago by dmethvin

Ticket #2612 addresses a related problem with IE7.

comment:6 Changed 4 years ago by Ben Hicks

I am also suffering from this issue with the current 1.3.2 release. A simple way to reproduce in a page with an Element 'test' is:

$('#test').html('<script>document.write("foobar");</script>');

Will this bug be rescheduled to a later release?

comment:7 Changed 3 years ago by scott.gonzalez

  • Cc scott.gonzalez@… added
  • Milestone changed from 1.3 to 1.4.3

comment:8 Changed 3 years ago by dmethvin

Scott González suggested we check for the scripts being already connected to the document. If they are connected we assume they've already run, if not we run them. That may work.

comment:9 Changed 3 years ago by SlexAxton

  • Keywords document ready script execution added
  • Priority changed from major to low
  • Status changed from new to open
  • Milestone changed from 1.4.3 to 1.5

comment:10 Changed 2 years ago by anonymous

This is a serious issue...

comment:11 Changed 2 years ago by anonymous

Before any wrap method call on any element containing inline script tags, thise tags need to be removed. So i tried something like this:

$(elem).find('script').each(function() {

if($(this).html().length > 0)

$(this).remove();

});

Question is if all <script> external script are executed twice or just inline functions?

comment:12 Changed 2 years ago by jitter

#7744 is a duplicate of this ticket.

comment:13 Changed 2 years ago by jitter

  • Keywords needsreview added
  • Priority changed from low to high
  • Version changed from 1.2.6 to 1.4.4
  • Component changed from core to manipulation
  • Description modified (diff)

 test case imported from 7744
 test case that was original added as attachment now in jsfiddle form

comment:14 Changed 2 years ago by danheberden

  • Milestone set to 1.next

comment:15 Changed 2 years ago by timmywil

#9134 is a duplicate of this ticket.

comment:16 Changed 23 months ago by john

  • Status changed from open to closed
  • Resolution set to wontfix

It seems like the only working solution here would be to go through the DOM and remove all scripts when you extract it from the page. We'll work to fix this explicitly in #9134 for .wrap().

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.