createPopup & event
<html>
<script>
function aa(ev)
{
//alert(event.srcElement.tagName);//It's occur a error
//alert(window.event.srcElement.tagName);//It's wrong
//alert(pop.event.srcElement.tagName);//It's wrong
//alert(pop.document.parentWindow.event.srcElement.tagName);//It's ok.retrieves parentWindow.
alert(ev.srcElement.tagName);//It's ok,attach event 's first parameter is window.event
//alert(11);
}
var pop = window.createPopup();
function x()
{
var tbl = pop.document.createElement("TABLE");
var tr = tbl.insertRow();
var td = tr.insertCell();
td.innerText = "xx";
//td.attachEvent("onmouseover",aa);//Is's ok.
td.attachEvent("onmouseover",parent.aa);
pop.document.body.insertAdjacentElement('afterbegin',tbl);
pop.show(0,0,100,100,document.body);
}
</script>
<body onload="x()">
</body>
</html>
<script>
function aa(ev)
{
//alert(event.srcElement.tagName);//It's occur a error
//alert(window.event.srcElement.tagName);//It's wrong
//alert(pop.event.srcElement.tagName);//It's wrong
//alert(pop.document.parentWindow.event.srcElement.tagName);//It's ok.retrieves parentWindow.
alert(ev.srcElement.tagName);//It's ok,attach event 's first parameter is window.event
//alert(11);
}
var pop = window.createPopup();
function x()
{
var tbl = pop.document.createElement("TABLE");
var tr = tbl.insertRow();
var td = tr.insertCell();
td.innerText = "xx";
//td.attachEvent("onmouseover",aa);//Is's ok.
td.attachEvent("onmouseover",parent.aa);
pop.document.body.insertAdjacentElement('afterbegin',tbl);
pop.show(0,0,100,100,document.body);
}
</script>
<body onload="x()">
</body>
</html>
可以看上面的注释,parent.aa还是aa并没有关系,而上面使用的三种方法不能引用到event.srcElement,event总是为空。原因是popup窗口只有document和isOpen两个属性,document再一级级展开下去,可是没有event的引用,真的不方便。
根据birdshome的资料,做如下修改,我们可以找回event:1、popwin.document.parentWindow.event;2、直接使用方法的第一个参数。