Ho un disperato bisogno di aiuto su questo.Perché questo JavaScript (usando document.open e document.write) funziona in Internet Explorer o Opera?
Ho creato un <sceneggiatura> che paralleli da vicino, e riproduce il problema di un altro più complesso <sceneggiatura> che ho scritto altrove.
Ecco ciò che fa:
- crea un <iframe> e inserisce in in un <div> sulla pagina
- crea e aggiunge un documento che <iframe>, che contiene uno script < > che definisce alcune funzioni (tra cui una funzione di callback e una funzione che carica uno script <esterno> utilizzando AJAX)
- quest'ultimo script esterno è solo una chiamata alla funzione di callback, che chiama una funzione che crea un documento e lo aggiunge all'ifframe < > in cui si trova; questo dovrebbe sovrascrivere in modo efficace lo script < >
I tre file coinvolti sono:
- http://troy.onespot.com/static/document_write/index.html (pagina principale)
- http://troy.onespot.com/static/document_write/main.js (il primo <sceneggiatura> che è caricato)
- http://troy.onespot.com/static/document_write/jsonp.js (lo script < > caricato dal metodo $ .ajax() di jQuery)
Tutto questo funziona in Firefox, Safari e Chrome. Dove si rompe è in Internet Explorer e Opera. Quello che succede è che la funzione render() in main.js viene eseguita e tutti e tre gli avvisi vengono attivati, ma il documento nell'ifframe < non viene sovrascritto. Non posso dire quale documento è stato creato o scritto, o se si è affatto.
Se aggiungo il codice di debug (come console.log (documento)) all'inizio della funzione render(), i browser funzionanti sembrano avere un handle sul documento esistente > iframe e elencano le proprietà incluse di seguito. Anche Internet Explorer sembra trovare un documento di qualche tipo. Non riesco proprio a capire perché non mi faccia sovrascrivere.
Potrebbe essere un problema di ambito? Forse sto usando i metodi document.write(), document.open() o document.close() in modo improprio, e Firefox e alcuni altri browser mi stanno semplicemente permettendo di farla franca?
Un possibile indizio: se prendo le viscere della funzione render() (cioè, li inserisco solo dopo load() in main.js), funziona bene. Questo mi suggerisce che non è come sto usando document.open(), ecc., Ma che in qualche modo quando viene eseguita la funzione callback(), l'oggetto documento non è disponibile, o è andato fuori campo, o qualcosa di simile.
Questo mi ha totalmente sconcertato, ed è per un progetto molto importante con una scadenza imminente. Non sono al di sopra di un trucco o di una soluzione se riesco a farmi uscire da questa marmellata. Qualsiasi aiuto o intuizione sarebbe ESTREMAMENTE apprezzato!
console.log() s 'elenco delle proprietà del 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
Hai riscontrato errori? –
Ciao meder - Non vedo errori in Internet Explorer o Opera. Entrambi visualizzano semplicemente l'alert() s nella funzione render(), ma non fanno nulla con il documento nello
dare un'occhiata a: https://stackoverflow.com/questions/12467151/iframe-not-rendering-in-ie9-mode-when-containing-page-is-in-quirks-mode –