Skip to main content

Bug Tracker

Side navigation

#12485 closed bug (notabug)

Opened September 07, 2012 12:04PM UTC

Closed September 09, 2012 11:27PM UTC

Last modified September 10, 2012 11:06AM UTC

html() include javascript twice

Reported by: maxou518 Owned by: maxou518
Priority: undecided Milestone: None
Component: unfiled Version: 1.8.1
Keywords: Cc:
Blocked by: Blocking:
Description

Hi,

Since v1.6 (also right for 1.8.1 version), if I do something like that :

#!python
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<script language="javascript" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
		<script language="javascript" type="text/javascript">
			$(document).ready(function() {
				$.ajax({
					url: "testscript.txt",
					dataType: "html",
					success: function(html) {
						$("#receveur").html(html);
						hello();
					}
				});
			});
		</script>
	</head>
	<body>
		<div id="receveur">
		</div>
	</body>
</html>

... where testscript.txt contains :

#!python
<div>
	<script language="javascript" type="text/javascript">
		function hello() {
			confirm("Hello");
		}
	</script>
	<h2>This is a title</h2>
</div>

... if I look with firebug, I find the function hello() implementation twice in the source. Is it normal or is it a bug ?

Attachments (0)
Change History (9)

Changed September 08, 2012 05:41PM UTC by mikesherov comment:1

owner: → maxou518
status: newpending

Thanks for contributing! Can you please provide a test case using a test like jsfiddle.net or jsbin.com or some other hosted solution so we can see the issue in action to determine if this is a bug? Thanks!

Changed September 09, 2012 04:56PM UTC by maxou518 comment:2

status: pendingnew

To be more exact, I see that in Firefox 15.0 and his firebug.

I don't succeed to do ajax calling with jsfiddle or other. But, I've found where the problem comes from!

It's in the globalEval function of core.js (from 1.6 version) :

// Evaluates a script in a global context
// Workarounds based on findings by Jim Driscoll
// http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context
globalEval: function( data ) {
	if ( data && rnotwhite.test( data ) ) {
		// We use execScript on Internet Explorer
		// We use an anonymous function so that context is window
		// rather than jQuery in Firefox
		( window.execScript || function( data ) {
			window[ "eval" ].call( window, data );
		} )( data );
	}
},

Firefox doesn't like ''window[ "eval" ].call( window, data );'' and put the content of ''data'' twice in the page.

If I use ''window.eval(data);'', it's ok.

Changed September 09, 2012 05:34PM UTC by mikesherov comment:3

status: newpending

I can not reproduce this: http://jsfiddle.net/5NcPp/1/ Please let me know what to change to show the bug happening.

Changed September 09, 2012 06:40PM UTC by maxou518 comment:4

_comment0: I see the bug on your page when I look with Firebug. It doesn't open the confirm twice (normal) but the hello implementation is in double.1347221469617499
status: pendingnew

I see the bug on your page when I look with Firebug. It doesn't open the confirm twice (normal) but the hello implementation is in double.

Screenshot : http://img824.imageshack.us/img824/456/image1ksm.jpg

Changed September 09, 2012 09:27PM UTC by mikesherov comment:5

status: newpending

I still can not reproduce... http://jsfiddle.net/5NcPp/2/ if it truly was in the source twice though, this new fiddle should print hi2. Does it? If not, I'm inclined to call this a bug in firebug and not jquery. Please let me know.

Changed September 09, 2012 10:48PM UTC by maxou518 comment:6

status: pendingnew

Nop, it print hi1.

Screenshot : http://img163.imageshack.us/img163/2208/image2gg.jpg

You suppose that if there are 2 hello functions, it will go in each of them. But, maybe it just goes in the first hello function found and never in the other. So, it will never print hi2. I've also tried with a append() on the title and it is executed just one time.

Me, I suppose that Firefox (not Firebug) have a bug with ''window[ "eval" ].call( window, data );'' in the version 15.0 (before, I don't know). If it's true, JQuery will need find something for this exception like it has ever done for IE and old chrome version (read http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context).

Changed September 09, 2012 11:27PM UTC by mikesherov comment:7

resolution: → notabug
status: newclosed

Sorry, but that not how JavaScript scoping works. If it was truly in there twice, it would have printed hi2. The only conclusion I can come to is that this isn't a bug in jQuery nor Firefox. Until we can prove this has some ill effect other than appearing incorrectly in the firebug console, I must close this as not a bug. Please feel free to reply if you can prove otherwise, and I'll gladly reopen! Thanks again for contributing!

Changed September 10, 2012 09:44AM UTC by maxou518 comment:8

So, why in this test : http://jsfiddle.net/vax82/ ... I just see "2!" and not "1...2!" ? He just call one hello function, not two.

Changed September 10, 2012 11:06AM UTC by mikesherov comment:9

my point wasn't that the function would be called twice... My point was that "a" would've been incremented twice. Firefox's eval shows the hoisted source code, that's all that's happening.