HTML and CSS Reference
In-Depth Information
try {
// mobile safari will not allow nodes to be transferred from one
// DOM to another so we must use adoptNode()
document . getElementById ( location ).
appendChild ( document . adoptNode ( newPage ));
} catch ( e ) {
// todo graceful degradation?
}
}
};
The target browser (Mobile Safari) correctly refuses to implicitly move a node from one
document to another. An error is raised if the new child node was created in a different
document. So this example uses adoptNode , and all is well.
So why iframe ? Why not just use innerHTML ? Even though innerHTML is now part of
the HTML5 spec, it is a dangerous practice to insert the response from a server (evil or
good) into an unchecked area. innerHTML has also been noted to fail intermittently on
iOS (just do a Google search on “ios innerhtml” to see the latest results) so it's best to
have a good workaround when the time comes.
Figure 3-11 shows the latest performance test from http://jsperf.com/ajax-response-
handling-innerhtml-vs-sandboxed-iframe . It shows that this sandboxed iframe approach
is just as fast, if not faster than innerHTML on many of today's top mobile browsers. Keep
in mind the measurement is operations per second, so higher scores are better.
Search WWH ::




Custom Search