Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
99
rated 0 times [  100] [ 1]  / answers: 1 / hits: 9062  / 10 Years ago, tue, july 8, 2014, 12:00:00

I'm getting SCRIPT5045: Assignment to read-only properties is not allowed in strict mode in IE 11 (latest Chrome works fine) in reference to the line



A.doc.head = A.doc.getElementsByTagName('HEAD')[0];.



I'm confused on how to fix it. I've included what should be the relevant code below.



(function (win, doc, arg) {
'use strict';
var A = win[arg.prefix] = {
'win': win,
'doc': doc,
'arg': arg,
'stu': {},
'fun': (function () {
return {
init: function () {
var scripts = A.doc.getElementsByTagName('SCRIPT'),
n = scripts.length,
i;
for (i = 0; i < n; i = i + 1) {
if (scripts[i].src.match(A.arg.src)) {
A.arg.script = scripts[i];
A.arg.options = A.fun.options();
break;
}
}
A.doc.head = A.doc.getElementsByTagName('HEAD')[0];
A.fun.structure();
},
// more functions
}())
};
A.fun.init();
}(window, document, {
'prefix': 'accescape_' + new Date().getTime(),
'src': '/widget.js',
'defaults': {
'language': 'en'
}
}));

More From » javascript

 Answers
1

document.head is a read-only property. If you want to shim it for oldIE, you'd better test for its nonexistence first:



if (!doc.head)
doc.head = doc.getElementsByTagName(head)[0];

[#44055] Monday, July 7, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bobbyw

Total Points: 456
Total Questions: 102
Total Answers: 113

Location: Bahrain
Member since Fri, Sep 16, 2022
2 Years ago
;