diff --git a/js/Readium.js b/js/Readium.js index 53c940a73..dec09be80 100644 --- a/js/Readium.js +++ b/js/Readium.js @@ -64,6 +64,39 @@ define(['readium_shared_js/globals', 'text!version.json', 'jquery', 'underscore' contentDocumentHtml = contentDocumentHtml.replace(/[\s]*<\/title>/g, '<title>TITLE'); contentDocumentHtml = contentDocumentHtml.replace(//g, 'TITLE'); + // When using the IE iframe loader all documents are loaded as html. EPUBs are valid XML so self closing + // XML tags must be converted to html in order to not break the browser. + var validSelfClosingTags = [ + 'area', + 'base', + 'br', + 'col', + 'command', + 'embed', + 'hr', + 'img', + 'input', + 'keygen', + 'link', + 'meta', + 'param', + 'source', + 'track', + 'wbr' + ]; + + var replacementFunc = function (tag) { + var tokens = tag.match(/^<([\S|\s]*?)\/>$/i)[1].split(' '); + var tagName = tokens[0]; + if (validSelfClosingTags.indexOf(tagName) === -1) { + return '<' + tokens.join(' ') + '>' + ''; + } else { + return tag; + } + }; + + contentDocumentHtml = contentDocumentHtml.replace(/<[\s]*[\S][\s]*[^>]*\/>/gi, replacementFunc); + return contentDocumentHtml; };