稍微扩展一下...
考虑进行轻微修改:
而HTML是否已加载还是未加载则需要判断。由于屏幕上看不到“goodbye universe - hello muiltiverse”,因此渲染肯定是待处理的,但是难道不必先加载
。
那么哪个先出现:加载和执行代码还是使用尚未加载的代码功能?
onload
作为window
属性有效,因为它是从对象中派生的,而不是像document
一样自我引用,即通过document
确定加载的问题情况。
PS.:以下情况下alert(...)
会失败吗?(个人经验教训):
注意:除非在同一个窗口中加载非常快...否则覆盖是当天的主旋律
因此,在使用相同命名的窗口时,实际需要的是什么:
window.open(URIstr1,"w") .
addEventListener('load',
function(){ alert(42);
window.open(URIstr2,"w") .
addEventListener('load',
function(){ alert(43);
window.open(URIstr3,"w") .
addEventListener('load',
function(){ alert(44);
/* ... */
} )
} )
} )
或者,对于每个连续的window.open
,请执行以下操作:
alert("在#警告显示待处理加载完成后或通过神的启示激发后按“确定”");
data:text/html;charset=utf-8,
<html content editable><head><script>
window.open(
"data:text/plain, has no DOM or" ,"Window"
) . addEventListener('load', function(){ alert(42) } )
window.open(
"data:text/plain, has no DOM but" ,"Window"
) . addEventListener('load', function(){ alert(4) } )
window.open(
"data:text/html,<html><body>has DOM and", "Window"
) . addEventListener('load', function(){ alert(2) } )
window.open(
"data:text/html,<html><body>has DOM and", "noWindow"
) . addEventListener('load', function(){ alert(1) } )
</script></head></html>
这段文字涉及到编程相关内容,强调了onload
在document
或window
属性上的差异。另一个需要注意的是保留XSS、跨站点脚本攻击和SOP、同源策略规则,可能允许加载HTML URI但不能修改其内容以进行检查。如果一个scURIple作为同一来源/站点的书签/脚本运行,则可能会成功。例如,从任意页面,此链接将进行加载但不太可能做alert('done')
:
<a href="javascript:window.open('view-source:http://google.ca') .
addEventListener( 'load', function(){ alert('done') } )"> src. vu </a>
但如果链接被加入书签,并在查看google.ca
页面时点击,它会同时实现两个功能。
测试环境:
window.navigator.userAgent =
Mozilla/5.0 (X11
window
上的load
事件。 - Paul S.window.addEventListener()
吗? - Yet Another UseraddEventListener
都被附加到了window
上(即使代码中的注释和控制台消息表明其中一个是要钩入文档的)。源代码中没有document.addEventListener('load' ...
。:-/ - david.binda