javascript和父/子窗口中带有“ with”关键字的有趣古怪内容
||
我注意到javascript中的\“ with \”关键字以及父窗口和子窗口之间的关系,特别是window.opener,有些特殊之处。我尚未从父窗口(仅是子窗口)进行测试,但是在下面的示例中值得注意的是-
父窗口(Parent.html):
// global scope
function ParentFunc() { alert(\"I am a parent function\"); }
子窗口(Child.html):
// global scope
var baseWin = window.opener;
// \"this\" keyword corresponds to Child.html when function below is called
function Child_Onclick_Func()
{
alert(\"Hi, from Child\");
with (baseWin)
{
ParentFunc();
alert(\"Hi, from Parent\");
}
alert(\"Hi, back to Child\");
}
在这种情况下,“ with”关键字切换到父窗口,第二个警报也向父窗口触发隐式onfocus。我没有意识到\“ with \\”会切换到父窗口,但是现在有意义。
没有找到相关结果
已邀请:
1 个回复
泻伴墓荒
您实际上是在调用
方法。