下面是一個例子有沒有辦法找出哪個iframe呼籲父母的JavaScript函數
parent.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>
T他更大的問題是,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'調查某些東西,但我不確定如果該函數的窗口對象可用於該路由,那麼我不確定關閉我的頭頂部。 –