Dec 19, 2012

Differents between window.top vs window.opener and window. Parent

12/19/2012 09:33:00 PM


Differents between window.top vs  window.opener  and window. Parent

window.top:-

The top property references the top level window. It comes in handy for targeting the top level when you are dealing with multiple window objects at different levels in the document.

<html>
<body>
<iframe id="subframe1" name="subframe1"></iframe>
<script type="text/javascript">
window.name = "my_window";
var subframe1 = document.getElementById('subframe1');
if(window.top.name == subframe1.name){
    alert("The subframe window is the top level window");
} else {
    alert("The subframe window is NOT the top level window");
}
</script>
</body>
</html>

window.opener:-
this is the window that opens or launches the current popup window.

Example:-
var w = open("blank.html", "blank", "height=50,width=300")
w.document.write("This window was opened by code on " + w.opener.location.href + ".")

Window.Parent:-
parent  = this is the parent frame of the current frame   or iframe. The parent frame may be the frameset window or another frame if you have nested frames. If not using frames, parent is the same as the current window or self

example
<!DOCTYPE html>
<html>
<head>
<script>
function openWin()
{
window.open('','','width=200,height=100');
alert(window.parent.location);
}
</script>
</head>
<body>

<input type="button" value="Open window" onclick="openWin()">

</body>
</html>








Written by

We are Creative Blogger Theme Wavers which provides user friendly, effective and easy to use themes. Each support has free and providing HD support screen casting.

0 comments:

Post a Comment

Recent Posts
Popular Articles

 

© 2013 MUNISH ORACLE DBA& .Net Developer. All rights resevered. Designed by Templateism

Back To Top