$.ajax({
type:'POST',
url: 'function.php',
success: function(data){
win = window.open("", "Window", "width=620,height=320,scrollbars=yes,titlebar=no,resizable=no");
if(win && !win.closed)
{
win.document.clear();
win.document.writeln(data);
win.document.writeln("<a href='javascript:self.close()'>close window</a>");
win.focus();
}
}
});
function.php
returns a html table.
In the parent form contains several links, when press each time on the link i need to refresh the content with new values based on the link id.
You might use jQuery to delete the content of the html and body tag:
$('body').empty();
$('html').empty();
That means, that function.php has to return a complete page or at least the body of a page via AJAX - to be inserted as new content with win.document.writeln(data);
(like you have it) or $("body").html(data);
Here's a JSBin that fixes your problem: http://jsbin.com/pekemecu/3/edit?html,js,output (tested on Google Chrome only)
Your popup wasn't getting cleared because your were calling getElementsByTagName
on the window object. Instead, you need to call it on the window.document
object. Also, don't set the html tag's innerHTML
to blank. If you do this, all your subsequent writeln
calls will not work.
Also, please declare variables using var
, otherwise all your variables get dumped into the global scope.