Joshxtothe4
Joshxtothe4

Reputation: 4193

creating a popupwindow from html, not a file

I have a php page that displays rows from a mysql db as a table. One of the fields contains HTML markup, and I would like to amke this row clickable and the html would open in a new popup window. What is the best way to do it, and is there a way to do it without writing the html to a file?

edit: this php page is actually part of an ajax app, so that is not a problem. I do not want to use jquery, as I would have to rewrite the application.

edit:

I have tried this again using the example below, and have failed. I know my script tag is wrong, but I am just echoing out row2 at the moment, so I think my logic is wrong before it ever gets to the javascript.

$sql="SELECT * FROM Auctions WHERE ARTICLE_NO ='$pk'";
$sql2="SELECT ARTICLE_DESC FROM Auctions WHERE ARTICLE_NO ='$pk'";
$htmlset = mysql_query($sql2);
$row2 = mysql_fetch_array($htmlset);
echo $row2;
/*echo '<script> child1 = window.open ("about:blank")
child1.document.write("$row2['ARTICLE_DESC']");
child1.document.close()*/

Upvotes: 0

Views: 309

Answers (4)

benlumley
benlumley

Reputation: 11382

if its a lot of data, worth thinking about loading it up via ajax when viewed to save selecting it and sending it to the user on every page load - which would be fairly easy with something like jquery as suggested already.

Upvotes: 0

Vincent Ramdhanie
Vincent Ramdhanie

Reputation: 103135

I would suggest using a Javascript library like jQuery since it simplifies this type of code and is cross browser compatible.

$(document).ready( function() {

$('#clicker').click( function() {
    myWindow=window.open('','','width=200,height=100')
    myWindow.document.write($("#content"));
    return false;
});

});

The html will be:

 <table>
    <tr>
       <td><div id="clicker">Click Here</div></td>
       <td><div id="content">This is the content</div></td>
     </tr>
 </table>

Upvotes: 0

HectorMac
HectorMac

Reputation: 6143

If you don't require a browser window (this suggestion involves a css modal box), you might want to consider one of the "lightbox" variations.

Thickbox can be used to load inline content from the page into a modal window. The link provides demo/details in how to implement inline content as well as other variations.

Upvotes: 0

Diodeus - James MacFarlane
Diodeus - James MacFarlane

Reputation: 114367

child1 = window.open ("about:blank")
child1.document.write("Moo!");
child1.document.close()

Upvotes: 4

Related Questions