Bug Tracker

Opened 10 years ago

Closed 7 years ago

#3105 closed bug (wontfix)

<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@…
Blocked by: Blocking:

Description (last modified by jitter)

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 (1)

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

Download all attachments as: .zip

Change History (17)

comment:1 Changed 10 years ago by dmethvin

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

Changed 10 years ago by dmethvin

Attachment: test-3105.html added

Test case for #3105

comment:2 Changed 10 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 10 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 10 years ago by dmethvin

Closed duplicate #2226 and pointed it to here.

comment:5 Changed 10 years ago by dmethvin

Ticket #2612 addresses a related problem with IE7.

comment:6 Changed 9 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 8 years ago by scottgonzalez

Cc: scott.gonzalez@… added
Milestone: 1.31.4.3

comment:8 Changed 8 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 8 years ago by SlexAxton

Keywords: document ready script execution added
Milestone: 1.4.31.5
Priority: majorlow
Status: newopen

comment:10 Changed 8 years ago by anonymous

This is a serious issue...

comment:11 Changed 8 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 8 years ago by jitter

#7744 is a duplicate of this ticket.

comment:13 Changed 8 years ago by jitter

Component: coremanipulation
Description: modified (diff)
Keywords: needsreview added
Priority: lowhigh
Version: 1.2.61.4.4

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

comment:14 Changed 7 years ago by danheberden

Milestone: 1.next

comment:15 Changed 7 years ago by timmywil

#9134 is a duplicate of this ticket.

comment:16 Changed 7 years ago by john

Resolution: wontfix
Status: openclosed

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().

Note: See TracTickets for help on using tickets.