开发者

how to check request come from parent window for child window

开发者 https://www.devze.com 2023-02-01 13:20 出处:网络
Please help I have develop two web pages.I want to check for open the child windo开发者_JAVA百科w. that come from parent window or direcltly copy paste the url of the page in javascript.window.opener

Please help I have develop two web pages.I want to check for open the child windo开发者_JAVA百科w. that come from parent window or direcltly copy paste the url of the page in javascript.


window.opener

should contain something(a window-object) if an window is a child-window of another(opened using window.open() ) .

So you have to check window.opener to see if a window is a child-window.


Assuming you have Page1.html and Page2.html, Page2.html can know if it was opened from within Page1.html by two ways:

<script type="text/javascript">
    if (typeof window.opener != "undefined")
        alert("I was opened from within " + window.opener.location.href);
    else if (document.referrer)
        alert("You came here from " + document.referrer);
</script>
0

精彩评论

暂无评论...
验证码 换一张
取 消