This question already has an answer here:
I have this code in my site and I would like to control the size of the _target window. I believe I need to use onClick but I am not sure. Newbie here.
<td class="recordCells"><?php echo '<a href="inventory/' . $row_rsInventory['PHOTO'] . '" target="_blank">' . '<img src="images/a-camera-icon.png"/>' . '</a>'; ?></td>
</div>
Yes, you're right about having to use onClick.
Your code should look like this:
<td class="recordCells">
<?php echo '<a href="inventory/' . $row_rsInventory['PHOTO'] . '" target="_blank" onClick="window.open(this.href, \'mywin\', \'width=500,height=500\'); return false;">' . '<img src="images/a-camera-icon.png"/>' . '</a>'; ?>
</td>
The slashes are for escaping the quotes, the rest is kind of self-explanatory. 'mywin' is the identifier for the window, in case you want to change the content later. We're returning false in the function, so the default click functionality is overriden.
You can use javascript open()
. By changing width
and height
you can adjust window size.
http://www.w3schools.com/jsref/met_win_open.asp
Create a click event on the element you want to click ie onclick="OpenWindow(URL_Parameter);".
Then, Create a script tag and a javascript function called OpenWindow()
<script type="text/javascript">
function OpenWindow(URL){
window.open(URL,name,specs,replace)
}
</script>
On the .Open() method, you can pass window sizes:
window.open(URL, "name", "width=200,height=100");