Given:
body = document.getElementsByTagName('body')[0];
iframe = document.createElement('iframe');
iframe.src = protocol + settings.scriptUrl + a;
iframe.height = 1;
iframe.width = 1;
iframe.scrolling = 'no';
iframe.frameborder = 0;
iframe.style = 'display:none';
body.appendChild(iframe);
I see TypeError: Attempted to assign to readonly property.
on the iframe.style =
line when testing in Safari, using strict mode.
While it might make sense to require a setter or similar for .style
, I can't seem to find any information about this being a requirement, and I can also can't find a recommendation for what I should be doing instead.
Some searching lead me to CSSStyleDeclaration.setProperty(), which may be what I want, but I'm not sure. And even if that's the right thing to do, I still haven't found any information on either which browsers support this; or how to make sure it works both with/without strict mode and in new/old browsers.
iframe.style.display = "none";
iframe.classList.add('hidden');
and CSS.hidden { display: none; }
. This will save you some trouble in the long way.