Bun*_*gle 7 javascript iframe scope document document.write
我迫切需要一些帮助.
我创建了一个非常平行的<script>,并重现了我在其他地方写过的另一个更复杂的<script>的问题.
这是它的作用:
涉及的三个文件是:
这一切都适用于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
bob*_*nce 11
如果我把render()函数的内容拿出来(也就是说,只需将它们放在main.js中的load()之后),这样就可以了.
在IE8中不适合我.如果我完全丢失了AJAX调用并且只是调用render()main.js,我会得到相同的结果.事实上,即使我用以下内容替换整个main.js:
document.write('hello!');
Run Code Online (Sandbox Code Playgroud)
无论是否打开文件,你好都不会出现!
如果我render在main.js 的调用中放置任何超时(甚至0),它就可以工作.另一方面,父文档的超时似乎没有做任何事情.
这种极端的怪异是由jQuery使用临时插入的<script>标记来执行jsonp.js中返回的代码引起的.如果您只是调用eval返回值而不是让jQuery执行它,它可以正常工作.
我发现缩小hello示例的相关问题由index.html证明:
<body>
<iframe name="foo"></iframe>
<script>
var idoc= frames['foo'].document;
idoc.open();
idoc.write('<body><script src="main.js"><\/script>');
idoc.close();
</script>
Run Code Online (Sandbox Code Playgroud)
与main.js包含:
document.write('foo');
Run Code Online (Sandbox Code Playgroud)
没有foo写的.(另一方面,内联脚本很好.)
如果idoc.close省略,它就有效.如果idoc.write('bar')添加了附加内容,则仅在IE bar中编写foo.如果我添加了两个bar和那个close电话,IE崩溃了.
总而言之,在自己编写的文档中使用时存在深层问题!尽可能避免使用它.可以是从父文档填充iframe的有用方法,但您不应该在子文档中真正需要它,您可以在自己使用DOM方法.document.writedocument.writedocument.open
| 归档时间: |
|
| 查看次数: |
15941 次 |
| 最近记录: |