<script>
$(document).ready(function() {
//////////////var newWin; // declaring global variable
////////////////////////////
$("#b_open").click(function(){
newWin = window.open("window-child-open-close.php");
})
//////////////
$("#b_close").click(function(){
newWin.close();
})
///////
})
</script>
Child window
<script>
$(document).ready(function() {
//////////////
$("#b2").click(function(){
self.close();
})
///////
})
</script>
window.opener
to access data from parent.
<script>
$(document).ready(function() {
////////////////
var str=parent.window.opener.$('#t1').val()
$('#d1').html("Parent Window Data = " + str);
//////////////
$("#b2").click(function(){
var sel=$('#t2').val();
window.opener.$('#t1').val(sel);
self.close();
})
///////
})
</script>
onunload
event to trigger a function which loads part of the page with fresh data from backend PHP file.
$("#b_open").click(function(){
newWin = window.open("window-child-reload.php");
newWin.onunload = my_load;
})
In our script we have used my_load() function to reload part of the page. Inside this function we increment the value of a text box showing number of times data is refreshed.
function my_load(){
if(newWin.location != "about:blank"){ // Don't do any thing if child window is open
var str=$('#t1').val();
str=parseInt(str)+1;
$("#t1").attr('value',str);
}
}
You can use load() to get fresh data from backend script inside above function.
Most Popular JQuery Scripts | |
1 | Two dependant list boxes |
2 | Calendar with Date Selection |
3 | Data change by Slider |
4 | Show & Hide element |