Opened 15 years ago
Closed 12 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: | [email protected]… |
Blocked by: | Blocking: |
Description (last modified by )
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)
Change History (17)
comment:1 Changed 14 years ago by
comment:2 Changed 14 years ago by
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 14 years ago by
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:6 Changed 14 years ago by
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 12 years ago by
Cc: | [email protected]… added |
---|---|
Milestone: | 1.3 → 1.4.3 |
comment:8 Changed 12 years ago by
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 12 years ago by
Keywords: | document ready script execution added |
---|---|
Milestone: | 1.4.3 → 1.5 |
Priority: | major → low |
Status: | new → open |
comment:11 Changed 12 years ago by
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:13 Changed 12 years ago by
Component: | core → manipulation |
---|---|
Description: | modified (diff) |
Keywords: | needsreview added |
Priority: | low → high |
Version: | 1.2.6 → 1.4.4 |
test case imported from 7744
test case that was original added as attachment now in jsfiddle form
comment:14 Changed 12 years ago by
Milestone: | → 1.next |
---|
comment:16 Changed 12 years ago by
Resolution: | → wontfix |
---|---|
Status: | open → closed |
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().
It's possible this is the cause of #3707 as well.