-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
61 lines (53 loc) · 1.54 KB
/
index.js
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
58
59
60
61
'use strict';
var AXO = require('axo');
/**
* Create a pre-configured htmlfile.
*
* @param {String} domain The document.domain of the document.
* @returns {htmlfile}
* @api public
*/
var htmlfile = module.exports = function create(domain) {
try { domain = domain || global.document.domain; }
catch (e) {
//
// Don't throw because we're not allowed to access domain info. WP is known
// to throw for this and ActiveX can be supported by Windows Phone + Mobile
// IE. In addition to that, this allows testing under Node.js
//
}
var htmlfile = new AXO('htmlfile')
, body = '<html><body>';
//
// Update the document.domain to the current domain if one is supplied or
// set. For localhost this is usually undefined.
//
if (domain) {
body += '<script>document.domain="'+ domain +'"\x3c/script>';
}
htmlfile.open();
htmlfile.write(body +'</body></html>');
htmlfile.close();
return htmlfile;
};
/**
* Destroy a given htmlfile.
*
* @api public
*/
htmlfile.destroy = function destroy() {
CollectGarbage();
};
/**
* Check if ActiveXObject is supported in browser. ActiveXObject is an IE only
* technology but it can still be disabled in the Internet Options of the
* browser so the only reliable way of detecting the support for it is to
* simply attempt to construct something with the ActiveXObject.
*
* @returns {Boolean}
* @api public
*/
htmlfile.supported = (function supported() {
try { return !!new AXO('htmlfile') && 'function' === typeof CollectGarbage; }
catch (e) { return false; }
}());