Side navigation
#10495 closed bug (migrated)
Opened October 14, 2011 02:35PM UTC
Closed October 20, 2014 11:46PM UTC
before() fails but native insertBefore() works ok
Reported by: | pferreir | Owned by: | pferreir |
---|---|---|---|
Priority: | low | Milestone: | None |
Component: | ajax | Version: | git |
Keywords: | Cc: | jaubourg | |
Blocked by: | Blocking: |
Description
While trying to inject the Facebook "like button" JS in a page in execution time, I got some funny behavior:
#!js var fjs = $('script:first'); $('<script/>').attr({'async': true, 'src': '//connect.facebook.net/en_US/all.js#xfbml=1&appId=xxx'}).insertBefore(fjs)
fails (same with the equivalent ''before()'' call).
While
#!js var fjs = $('script:first').get(0); var e = $('<script/>').attr({'async': true, 'src': '//connect.facebook.net/en_US/all.js#xfbml=1&appId=xxx'}).get(0); fjs.parentNode.insertBefore(e, fjs)
works just ok.
I tried different combinations of native/jQuery elements and they all fail. This happens at least since 1.6.1.
Attachments (0)
Change History (8)
Changed October 14, 2011 02:36PM UTC by comment:1
Changed October 14, 2011 03:05PM UTC by comment:2
owner: | → pferreir |
---|---|
status: | new → pending |
Why not use $.getScript
? http://api.jquery.com/jQuery.getScript/
Can you provide a complete test case on jsfiddle.net? That would help us evaluate the problem.
Changed October 17, 2011 10:11AM UTC by comment:3
status: | pending → new |
---|
Hello,
Here is a small example: http://jsfiddle.net/RQVsa/
The uncommented code should work (show the "Like" button), while the commented on should fail.
I tried $.getScript
, with no success...
Changed October 19, 2011 05:58PM UTC by comment:4
cc: | → jaubourg |
---|---|
component: | unfiled → ajax |
priority: | undecided → low |
We filter out scripts in manipulation. getScript should be used, but we remove hashes from the url. I'm not sure why, but it's been there a while.
Changed October 20, 2011 09:16PM UTC by comment:5
status: | new → open |
---|
Seems valid enough to keep open, until we figure out why we're removing the hash.
Changed January 06, 2013 09:14PM UTC by comment:6
Okay, this gives me an error from Facebook because of the xxx id:
This gives the same error and doesn't have the hash as timmywil said:
Since the script hasn't yet been executed the .insertBefore()
is making the ajax request to request the script, but since the hash is stripped it's never going to see the correct id.
@jaubourg, do you know why we're stripping off the hash? Is there a specific reason for it, or just an omission?
Changed January 08, 2013 03:48PM UTC by comment:7
Changed October 20, 2014 11:46PM UTC by comment:8
resolution: | → migrated |
---|---|
status: | open → closed |
Migrated to https://github.com/jquery/jquery/issues/1732
I forgot to add that in the first case the element seems to be added to the DOM only to be immediately removed.