@@ -13,7 +13,9 @@ jQuery.support = (function() {
1313 support ,
1414 fragment ,
1515 body ,
16- bodyStyle ,
16+ testElementParent ,
17+ testElement ,
18+ testElementStyle ,
1719 tds ,
1820 events ,
1921 eventName ,
@@ -136,9 +138,11 @@ jQuery.support = (function() {
136138 // Figure out if the W3C box model works as expected
137139 div . style . width = div . style . paddingLeft = "1px" ;
138140
139- // We use our own, invisible, body
140- body = document . createElement ( "body" ) ;
141- bodyStyle = {
141+ body = document . getElementsByTagName ( "body" ) [ 0 ] ;
142+ // We use our own, invisible, body unless the body is already present
143+ // in which case we use a div (#9239)
144+ testElement = document . createElement ( body ? "div" : "body" ) ;
145+ testElementStyle = {
142146 visibility : "hidden" ,
143147 width : 0 ,
144148 height : 0 ,
@@ -147,11 +151,19 @@ jQuery.support = (function() {
147151 // Set background to avoid IE crashes when removing (#9028)
148152 background : "none"
149153 } ;
150- for ( i in bodyStyle ) {
151- body . style [ i ] = bodyStyle [ i ] ;
154+ if ( body ) {
155+ jQuery . extend ( testElementStyle , {
156+ position : "absolute" ,
157+ left : - 1000 ,
158+ top : - 1000
159+ } ) ;
160+ }
161+ for ( i in testElementStyle ) {
162+ testElement . style [ i ] = testElementStyle [ i ] ;
152163 }
153- body . appendChild ( div ) ;
154- documentElement . insertBefore ( body , documentElement . firstChild ) ;
164+ testElement . appendChild ( div ) ;
165+ testElementParent = body || documentElement ;
166+ testElementParent . insertBefore ( testElement , testElementParent . firstChild ) ;
155167
156168 // Check if a disconnected checkbox will retain its checked
157169 // value of true after appended to the DOM (IE6/7)
@@ -210,8 +222,8 @@ jQuery.support = (function() {
210222 }
211223
212224 // Remove the body element we added
213- body . innerHTML = "" ;
214- documentElement . removeChild ( body ) ;
225+ testElement . innerHTML = "" ;
226+ testElementParent . removeChild ( testElement ) ;
215227
216228 // Technique from Juriy Zaytsev
217229 // http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/
0 commit comments