diff --git a/CHANGELOG b/CHANGELOG index e011e29..77bb59d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Make sure `getAttribute` is used without flag when accessing the "type" attribute of an iframe (IE throws error otherwise). [#118 state:resolved] (Zekid, kangax) + * String#gsub should escape RegExp metacharacters when the first argument is a string. [#469 state:resolved] (michael, kangax) * Fix order of replacement in String#unescapeHTML [#544 state:resolved] (SWeini, kangax) diff --git a/src/dom/dom.js b/src/dom/dom.js index 7e0f0bd..2e78d4f 100644 --- a/src/dom/dom.js +++ b/src/dom/dom.js @@ -274,20 +274,43 @@ Element.Methods = { return id; }, - readAttribute: function(element, name) { - element = $(element); - if (Prototype.Browser.IE) { - var t = Element._attributeTranslations.read; - if (t.values[name]) return t.values[name](element, name); - if (t.names[name]) name = t.names[name]; - if (name.include(':')) { - return (!element.attributes || !element.attributes[name]) ? null : - element.attributes[name].value; - } - } + readAttribute: (function(){ - return element.getAttribute(name); - }, + var iframeGetAttributeThrowsError = (function(){ + var el = document.createElement('iframe'), + isBuggy = false; + + document.documentElement.appendChild(el); + try { + el.getAttribute('type', 2); + } catch(e) { + isBuggy = true; + } + document.documentElement.removeChild(el); + el = null; + return isBuggy; + })(); + + return function(element, name) { + element = $(element); + // check boolean first, to get out of expression faster + if (iframeGetAttributeThrowsError && + name === 'type' && + element.tagName.toUpperCase() == 'IFRAME') { + return element.getAttribute('type'); + } + if (Prototype.Browser.IE) { + var t = Element._attributeTranslations.read; + if (t.values[name]) return t.values[name](element, name); + if (t.names[name]) name = t.names[name]; + if (name.include(':')) { + return (!element.attributes || !element.attributes[name]) ? null : + element.attributes[name].value; + } + } + return element.getAttribute(name); + } + })(), writeAttribute: function(element, name, value) { element = $(element); diff --git a/test/unit/dom_test.js b/test/unit/dom_test.js index 4e02c5f..bfbee38 100644 --- a/test/unit/dom_test.js +++ b/test/unit/dom_test.js @@ -933,6 +933,11 @@ new Test.Unit.Runner({ var table = $('write_attribute_table'); this.assertEqual('4', table.readAttribute('cellspacing')); this.assertEqual('6', table.readAttribute('cellpadding')); + + var el = document.createElement('iframe'); + document.body.appendChild(el); + alert(Element.readAttribute(el, 'type')); + document.body.removeChild(el); }, testElementWriteAttribute: function() {