简体   繁体   中英

javascript new popup page in php

I'm new in web programming and I have some problem. I want to open a new popup php page from a link clicked but is not work..

from this link

echo '<td><a href="#" onClick = "open("../common/sqlDetail_Inform_Reservation.php?id='.$row['Reservation_ID'].'");">OPEN</a></td>';

Script function

function open(url) {
      var popup = window.open(url, "_blank", "width=200, height=200") ;
      popup.location = url;
    }

Best regard : D

You have a quotes issue. You need to escape your double quotes that inside a double quoted string:

echo '<td><a href="#" onClick = "open(\"../common/sqlDetail_Inform_Reservation.php?id='.$row['Reservation_ID'].'\");">OPEN</a></td>';

您与引号有冲突,请尝试以下操作:

echo '<td><a href="#" onClick = "open(\'../common/sqlDetail_Inform_Reservation.php?id='.$row['Reservation_ID'].'\');">OPEN</a></td>';

This is a elegant solution to avoid to many click handlers,it uses the new attribute data-SOMETHING to store your id.if you want more compatibility you can also use the rel attribute or title or whatever to store the id. less code,faster javascript,easy to edit later.

<table>
<?php
while($row blabla ){
 echo "<tr>
  <td>".$row['bla1']."</td>
  <td data-id=\"".$row['Reservation_ID']."\">open</td>
 </tr>";
}
?>
</table>
<script>
function open(e){
 if(e.target.dataset['id']){
  window.open('blabla/Reservation.php?id='+e.target.dataset['id']);
 }
}
document.getElementsByTagName('table')[0].addEventListener('click',open,false)
</script>

if you don't understand something just ask

example in javascript...

http://jsfiddle.net/V5Kn5/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM