我非常需要這個幫助。爲什麼JavaScript(使用document.open和document.write)不能在Internet Explorer或Opera中使用?
我創建了一個<腳本>緊密平行,並再現的問題,另一個更復雜的<腳本>,我已經在其他地方寫的。
下面是它做什麼:
- 創建一個<IFRAME>並插入在成<DIV>頁面
- 上創建和附加一個文件到<IFRAME>,其中包含一個<腳本>定義了幾個函數(包括回調函數和使用AJAX加載外部<腳本>的函數)
- 後者的外部腳本只是對回調函數的調用,該函數調用一個函數來創建文檔並將其附加到 iframe >它所在的位置;這應該有效地覆蓋<腳本>
涉及的三個文件分別是:
- http://troy.onespot.com/static/document_write/index.html(主頁)
- http://troy.onespot.com/static/document_write/main.js(第一<腳本>說的加載)
- http://troy.onespot.com/static/document_write/jsonp.js( <腳本>由jQuery的$ .ajax()方法加載)
這一切都適用於Firefox,Safari和Chrome。它在Internet Explorer和Opera中出現故障。會發生什麼情況是main.js中的render()函數會執行,並且會觸發所有三個警報,但iframe >中的文檔不會被覆蓋。我無法分辨正在創建或寫入的文檔,或者根本沒有。
如果我在render()函數的開頭添加調試代碼(如console.log(document)),工作的瀏覽器似乎可以處理現有的iframe >文檔並列出下麪包含的屬性。 Internet Explorer也似乎找到某種文件。我只是不知道爲什麼它不讓我覆蓋它。
它可能是一個範圍問題?也許我不正確地使用document.write(),document.open()或document.close()方法,而Firefox和其他一些瀏覽器只是讓我擺脫它?一個可能的線索:如果我把render()函數的內容拿出來(即將它們放在main.js中的load()之後),這可以正常工作。這向我暗示,這不是我如何使用document.open()等,但不知何故,在執行callback()函數時,文檔對象不可用,或已超出作用域,或類似的東西。
這讓我非常難過,這是一個非常重要的項目,即將到期。如果能讓我擺脫這種困境,我不會受到黑客或解決方法的困擾。任何幫助或見解將極其讚賞!文檔屬性的
的console.log()的上市:
ATTRIBUTE_NODE: 2 CDATA_SECTION_NODE: 4 COMMENT_NODE: 8 DOCUMENT_FRAGMENT_NODE: 11 DOCUMENT_NODE: 9 DOCUMENT_POSITION_CONTAINED_BY: 16 DOCUMENT_POSITION_CONTAINS: 8 DOCUMENT_POSITION_DISCONNECTED: 1 DOCUMENT_POSITION_FOLLOWING: 4 DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC: 32 DOCUMENT_POSITION_PRECEDING: 2 DOCUMENT_TYPE_NODE: 10 ELEMENT_NODE: 1 ENTITY_NODE: 6 ENTITY_REFERENCE_NODE: 5 NOTATION_NODE: 12 PROCESSING_INSTRUCTION_NODE: 7 TEXT_NODE: 3 URL: "http://localhost/projects/test/ajax_loader/document_write/index.html" activeElement: HTMLBodyElement addEventListener: function addEventListener() { adoptNode: function adoptNode() { alinkColor: "" all: HTMLCollection anchors: HTMLCollection appendChild: function appendChild() { applets: HTMLCollection attributes: null baseURI: "http://localhost/projects/test/ajax_loader/document_write/index.html" bgColor: "" body: HTMLBodyElement captureEvents: function captureEvents() { characterSet: "UTF-8" charset: "UTF-8" childNodes: NodeList clear: function clear() { cloneNode: function cloneNode() { close: function close() { compareDocumentPosition: function compareDocumentPosition() { compatMode: "BackCompat" cookie: "__gads=ID=62bb88ab20ac9451:T=1256683145:S=ALNI_Mbso-nFjAvRzYhCSwhiuaDh84G8CA" createAttribute: function createAttribute() { createAttributeNS: function createAttributeNS() { createCDATASection: function createCDATASection() { createComment: function createComment() { createDocumentFragment: function createDocumentFragment() { createElement: function createElement() { createElementNS: function createElementNS() { createEntityReference: function createEntityReference() { createEvent: function createEvent() { createExpression: function createExpression() { createNSResolver: function createNSResolver() { createNodeIterator: function createNodeIterator() { createProcessingInstruction: function createProcessingInstruction() { createRange: function createRange() { createTextNode: function createTextNode() { createTreeWalker: function createTreeWalker() { defaultCharset: "iso-8859-1" defaultView: DOMWindow designMode: "off" dir: "" dispatchEvent: function dispatchEvent() { doctype: null documentElement: HTMLHtmlElement documentURI: "http://localhost/projects/test/ajax_loader/document_write/index.html" domain: "localhost" elementFromPoint: function elementFromPoint() { embeds: HTMLCollection evaluate: function evaluate() { execCommand: function execCommand() { fgColor: "" firstChild: HTMLHtmlElement forms: HTMLCollection getCSSCanvasContext: function getCSSCanvasContext() { getElementById: function getElementById() { getElementsByClassName: function getElementsByClassName() { getElementsByName: function getElementsByName() { getElementsByTagName: function getElementsByTagName() { getElementsByTagNameNS: function getElementsByTagNameNS() { getOverrideStyle: function getOverrideStyle() { getSelection: function getSelection() { hasAttributes: function hasAttributes() { hasChildNodes: function hasChildNodes() { hasFocus: function hasFocus() { height: 150 images: HTMLCollection implementation: DOMImplementation importNode: function importNode() { inputEncoding: "UTF-8" insertBefore: function insertBefore() { isDefaultNamespace: function isDefaultNamespace() { isEqualNode: function isEqualNode() { isSameNode: function isSameNode() { isSupported: function isSupported() { jQuery1258269389622: 2 lastChild: HTMLHtmlElement lastModified: "" linkColor: "" links: HTMLCollection localName: null location: Location lookupNamespaceURI: function lookupNamespaceURI() { lookupPrefix: function lookupPrefix() { namespaceURI: null nextSibling: null nodeName: "#document" nodeType: 9 nodeValue: null normalize: function normalize() { open: function open() { ownerDocument: null parentElement: null parentNode: null plugins: HTMLCollection preferredStylesheetSet: null prefix: null previousSibling: null queryCommandEnabled: function queryCommandEnabled() { queryCommandIndeterm: function queryCommandIndeterm() { queryCommandState: function queryCommandState() { queryCommandSupported: function queryCommandSupported() { queryCommandValue: function queryCommandValue() { querySelector: function querySelector() { querySelectorAll: function querySelectorAll() { readyState: "complete" referrer: "http://localhost/projects/test/ajax_loader/document_write/index.html" releaseEvents: function releaseEvents() { removeChild: function removeChild() { removeEventListener: function removeEventListener() { replaceChild: function replaceChild() { scripts: HTMLCollection selectedStylesheetSet: null styleSheets: StyleSheetList textContent: null title: " Page" vlinkColor: "" width: 300 write: function write() { writeln: function writeln() { xmlEncoding: null xmlStandalone: false xmlVersion: null
您是否遇到任何錯誤? – 2009-11-15 08:07:39
嗨meder - 我在Internet Explorer或Opera中看不到任何錯誤。兩者都只是在render()函數中顯示alert(),但不要對
看看: https://stackoverflow.com/questions/12467151/iframe-not-rendering-in-ie9-mode-when-containing-page-is-in-quirks-mode – 2014-10-02 16:47:55