Skip to main content

Bug Tracker

Side navigation

#3105 closed bug (wontfix)

Opened June 30, 2008 03:37PM UTC

Closed July 11, 2011 05:48PM UTC

<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@gmail.com
Blocked by: Blocking:
Description

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 January 06, 2009 10:52PM UTC.

    Test case for #3105

Change History (16)

Changed December 19, 2008 03:15AM UTC by dmethvin comment:1

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

Changed January 06, 2009 10:55PM UTC by dmethvin comment:2

owner: → 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.

Changed January 11, 2009 07:15PM UTC by john comment:3

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.

Changed January 15, 2009 02:04AM UTC by dmethvin comment:4

Closed duplicate #2226 and pointed it to here.

Changed January 21, 2009 04:31AM UTC by dmethvin comment:5

Ticket #2612 addresses a related problem with IE7.

Changed April 01, 2009 09:14AM UTC by Ben Hicks comment:6

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?

Changed August 19, 2010 02:33PM UTC by scottgonzalez comment:7

cc: → scott.gonzalez@gmail.com
milestone: 1.31.4.3

Changed September 25, 2010 02:25PM UTC by dmethvin comment:8

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.

Changed October 23, 2010 09:49PM UTC by SlexAxton comment:9

keywords: → document ready script execution
milestone: 1.4.31.5
priority: majorlow
status: newopen

Changed November 24, 2010 10:16AM UTC by anonymous comment:10

This is a serious issue...

Changed November 24, 2010 10:35AM UTC by anonymous comment:11

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?

Changed December 13, 2010 07:32PM UTC by jitter comment:12

#7744 is a duplicate of this ticket.

Changed December 13, 2010 07:41PM UTC by jitter comment:13

component: coremanipulation
description: 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 \ \ 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 \ \
keywords: document ready script executiondocument ready script execution needsreview
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

Changed March 31, 2011 03:24PM UTC by danheberden comment:14

milestone: → 1.next

Changed May 06, 2011 03:50PM UTC by timmywil comment:15

#9134 is a duplicate of this ticket.

Changed July 11, 2011 05:48PM UTC by john comment:16

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