【发布时间】:2019-06-14 07:36:53
【问题描述】:
这是一个例子
父.html
<script>
function printWhoCalledMe() {
console.log(???); // what goes here that will identify the caller?
}
<iframe src="iframe1.html"></iframe>
<iframe src="iframe2.html"></iframe>
iframe1.html
<script>
window.parent.printWhoCalledMe();
</script>
iframe2.html
<script>
window.parent.printWhoCalledMe();
</script>
更大的问题是I have a test harness that runs a bunch of tests, one at a time, in an iframe。每次测试调用window.parent.reportOnTest(success)
我正在研究通过在超过 1 个 iframe 中运行测试来并行化测试,但我必须通过每个测试,目前是 1000 个测试,并将它们的调用从 window.parent.reportOnTest(success) 更改为 window.parent.reportOnTest(success, window.location.href) 之类的东西像这样。
我想知道是否有办法在不修改测试的情况下找出哪个测试正在调用父级。
注意:我试过了
function printWhoCalledMe() {
console.log(window.location.href);
}
但这会打印父级的 href。
【问题讨论】:
-
可能值得通过
arguments.callee.caller进行调查,但我不确定该函数的窗口对象是否可以通过该路径获得。
标签: javascript html iframe