dynamic - How can we change the HTML table contents dynamically using javascript? -
how can dynamically change html table contents if table in pop displayed while pressing button?
i know can change content using below function
function change(){ var x=document.getelementbyid('tbl').rows var y=x[0].cells y[0].innerhtml="new content" }
but possible when table on same window. in case of pop not change.
you can access elements in window open using windowref.document.getelementbyid(...)
so:
<script type="text/javascript"> // global used here, use in closure in rl var popupwindow; function popwin() { var content = '<title>popup window</title>' + '<table id="tbl">' + '<tr><td>row 0 cell 0<td>row 0 cell 1' + '</table>'; var newwin = window.open('','newwin'); newwin.document.write(content); newwin.document.close(); return newwin; } </script> <p>some examples of accessing content of popup created script in page</p> <input type="button" value="open popup" onclick=" popupwindow = popwin(); "> <input type="button" value="change table content" onclick=" if (popupwindow) { var tbl = popupwindow.document.getelementbyid('tbl'); tbl.rows[0].cells[0].firstchild.data = 'hey hey!'; } "> <input type="button" value="close popup" onclick=" if (popupwindow) { popupwindow.close(); popupwindow = null; } ">
however it's worth noting users hate popups, block them unless initiated user action (click or similar), , may close them without knowing. also, can above windows open, can't randomly change content, or access, any window.
Comments
Post a Comment