Skip to main content

Bug Tracker

Side navigation

#10176 closed bug (fixed)

Opened August 31, 2011 10:36AM UTC

Closed October 12, 2011 04:07AM UTC

Last modified February 28, 2013 07:27AM UTC

Injected script tag is evaluated twice

Reported by: anonymous Owned by: timmywil
Priority: high Milestone: 1.7
Component: attributes Version: 1.6.2
Keywords: Cc:
Blocked by: Blocking:
Description

When injecting a script tag into the head tag the injected script is evaluated twice in IE 7 & 8 using jquery 1.6.2. This did not happen in jquery 1.4.2. Note that this only happens when the files are stored locally. It works correctly in IE9.

The following should produce one alert, but in IE 7 & 8 with jquery 1.6.2 it shows two alerts:

test.html:
<html>
   <head>
      <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
      <script type="text/javascript">      
         $(function() {
            var script = jQuery("<script></scr" + "ipt>")
               .attr("type", "text/javascript")
               .attr("src", "fragment.js");
            jQuery("head").append(script);            
         });      
      </script>
   </head>   
   <body></body>
</html>


fragment.js:
alert("fragment");
Attachments (0)
Change History (9)

Changed August 31, 2011 02:06PM UTC by timmywil comment:1

component: unfiledattributes
owner: → anonymous
priority: undecidedlow
status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a reduced test case on jsFiddle to help us assess your ticket.

Additionally, be sure to test against the jQuery Edge version to ensure the issue still exists. To get you started, use this boilerplate: http://jsfiddle.net/FrKyN/ Open the link and click to "Fork" (in the top menu) to get started.

You say this didn't happen in 1.4.2? The script is loaded as soon as src is set so I'm not sure how 1.4.2 could be any different than 1.6.2.

Changed August 31, 2011 03:01PM UTC by anonymous comment:2

status: pendingnew

Yes, I should have said: because this bug only occurs when the files are local and jsFiddle has, as far as I know, no way of simulating the file:// protocol I could not submit a test case in jsFiddle.

If I run the code through a debugger and puts a break point in the fragment it gets called from two places in jQuery:

  • From the function findInputs() at line 6021. This makes no sense to me.
  • From the function globalEval() at line 603. The same function that gets called in 1.4.2.

I was however mistaken about IE9, it does the same thing.

Changed August 31, 2011 03:07PM UTC by anonymous comment:3

http://code.jquery.com/jquery-git.js, which I assume is "jQuery Edge" does the same thing.

Changed September 02, 2011 09:37AM UTC by anonymous comment:4

The problem seems to be the fix for #8060. On line 6062 in jQuery 1.6.3 elem.getElementsByTagName("input") is called and if elem is a script tag the content will apparently be evaluated. My fix is to ignore script tags:

6061c6061
<       } else if ( "getElementsByTagName" in elem ) {
---
>       } else if ( "getElementsByTagName" in elem && elem.nodeName !== "SCRIPT") {

Changed September 02, 2011 03:21PM UTC by dmethvin comment:5

milestone: None1.7
priority: lowhigh
status: newopen

Changed September 22, 2011 02:17PM UTC by timmywil comment:6

owner: anonymoustimmywil
status: openassigned

I'll take this one too.

Changed October 12, 2011 04:07AM UTC by timmywil comment:7

resolution: → fixed
status: assignedclosed

Do not call getElements on a script tag. Avoids unnecessary execution. Fixes #10176.

Changeset: 3ad0ba62f03ff3d7aec7d3dfb25492cdf33350a7

Changed March 08, 2012 02:07PM UTC by anonymous comment:8

#!html
       <ul class="changes"><li>

    
 <strong>Changed</strong> from Review to <i>Test Case </i><a style='color:white' href='http://obtenir-rio.info/'>rio orange</a>
<a style='color:white' href='http://portabilite.info'>portabilite du numero</a>
<a style='color:white'  href='http://calcul-imc.info'>imc</a></li><li>
      <strong>Status</strong> changed from <em>reopened</em> to <em>closed</em>
 <a style='color:white' href='http://le-meilleur-forfait.com/'>forfait mobile</a>
<a style='color:white' href='http://le-meilleur-forfait.com/sans_engagement'>forfait sans engagement</a>
<a style='color:white'  href='http://le-meilleur-forfait.com/illimite'>forfait illimite</a>
<a style='color:white'  href='http://le-meilleur-forfait.com/sms_illimite'>sms illimite</a>
<a style='color:white'  href='http://le-meilleur-forfait.com/internet'>forfait internet mobile</a>
<a style='color:white'  href='http://le-meilleur-forfait.com/bloque'>forfait bloque</a>
<a style='color:white'  href='http://le-meilleur-forfait.com/blackberry'>forfait blackberry</a></li></ul>

Changed February 28, 2013 07:27AM UTC by anonymous comment:9

The problem alrady exist on jquery 1.9.1 on IE9.

Nothing is changed from initial post