Por que esse JavaScript (usando document.open e document.write) não funciona no Internet Explorer ou no Opera?

Eu preciso desesperadamente de alguma ajuda sobre isso.

Eu criei um <script> que paralela de perto, e reproduz o problema de, outro <script> mais complexo que eu escrevi em outro lugar.

Veja o que faz:

cria um <iframe> e insere em um <div> na páginacria e anexa um documento a esse <iframe>, que contém um <script> que define algumas funções (incluindo uma função de retorno de chamada e uma função que carrega um <script> externo usando o AJAX)o último script externo é apenas uma chamada para a função de retorno de chamada, que chama uma função que cria um documento e o anexa ao <iframe>; isso deve substituir efetivamente o <script>

Os três arquivos envolvidos são:

http://troy.onespot.com/static/document_write/index.html (a página principal)http://troy.onespot.com/static/document_write/main.js (o primeiro <script> carregado)http://troy.onespot.com/static/document_write/jsonp.js (o <script> carregado pelo método $ .ajax () do jQuery)

Isso tudo funciona no Firefox, Safari e Chrome. Onde ele está no Internet Explorer e no Opera. O que acontece é que a função render () em main.js é executada e todos os três alertas são disparados, mas o documento no <iframe> não é sobrescrito. Não sei dizer em qual documento está sendo criado ou gravado, ou se algum está sendo criado.

Se eu adicionar código de depuração (como console.log (documento)) no início da função render (), os navegadores de trabalho parecem obter um identificador no documento <iframe> existente e listar as propriedades incluídas abaixo. O Internet Explorer também parece encontrar algum tipo de documento. Eu simplesmente não posso dizer por que não está me deixando substituí-lo.

Poderia ser uma questão de escopo? Talvez eu esteja usando os métodos document.write (), document.open () ou document.close () indevidamente, e o Firefox e alguns outros navegadores estão apenas me deixando escapar disso?

Uma pista possível: se eu tirar a coragem da função render () (ou seja, basta colocá-las após load () em main.js), isso funciona bem. Isso sugere que não é como eu estou usando document.open (), etc., mas que de alguma forma, no momento em que a função callback () é executada, o objeto de documento não está disponível, ou saiu do escopo, ou algo assim.

Isso me deixou totalmente perplexo, e é por um projeto muito importante com um prazo iminente. Eu não estou acima de um hack ou solução alternativa se me tirar dessa jam. Qualquer ajuda ou insight seria extremamente apreciado!

Listagem do console.log () das propriedades do documento:

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

questionAnswers(6)

yourAnswerToTheQuestion