File size: 1,953 Bytes
c02f046 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | uitest.define('sniffer', ['top'], function(top) {
function jsUrlDoesNotChangeLocation(callback) {
var tmpFrame = top.document.createElement("iframe");
top.document.body.appendChild(tmpFrame);
// Opening and closing applies the
// location href from the top window to the iframe.
tmpFrame.contentWindow.document.open();
tmpFrame.contentWindow.document.close();
// The timeout is needed as FF triggers the onload
// from the previous document.open/close
// even if we set the onload AFTER we did document.open/close!
top.setTimeout(changeHrefAndAddOnLoad, 0);
function changeHrefAndAddOnLoad() {
/*jshint scripturl:true*/
if (tmpFrame.attachEvent) {
tmpFrame.attachEvent("onload", onloadCallback);
} else {
tmpFrame.onload = onloadCallback;
}
tmpFrame.contentWindow.location.href="javascript:'<html><body>Hello</body></html>'";
}
function onloadCallback(){
/*jshint scripturl:true*/
var result = tmpFrame.contentWindow.location.href.indexOf('javascript:')===-1;
tmpFrame.parentNode.removeChild(tmpFrame);
callback(result);
}
}
function browserSniffer() {
var useragent = top.navigator.userAgent.toLowerCase(),
android = /android/i.test(useragent),
ieMatch = /MSIE\s+(\d+)/i.exec(useragent),
ff = /firefox/i.test(useragent);
return {
android: android,
ie: ieMatch && parseInt(ieMatch[1],10),
ff: ff
};
}
function detectFeatures(readyCallback) {
jsUrlDoesNotChangeLocation(function(jsUrlSupported) {
readyCallback({
jsUrl: jsUrlSupported,
browser: browserSniffer()
});
});
}
return detectFeatures;
}); |