drz73366
drz73366
2014-11-28 06:57
浏览 46

window.open什么都不做

I'm trying to show some info in a pop-up window usig a window.open.. but when I click nothing happens.

This is the function that opens a new window.

function goNewWin(sell_code){

// Set height and width
var NewWinHeight=1000;
var NewWinWidth=1000;

// Place the window
var NewWinPutX=10;
var NewWinPutY=10;

//Get what is below onto one line

TheNewWin =window.open("renovations_history.php?sell_code=" + sell_code,
'Renovaciones','fullscreen=yes,toolbar=no,location=no,status=no,menubar=no,scrollbars=no');

//Get what is above onto one line

TheNewWin.resizeTo(NewWinHeight,NewWinWidth);
TheNewWin.moveTo(NewWinPutX,NewWinPutY);

}
</script>

Here's the HTML, with some PHP.

<form>
  <input type="button" value="Renovaciones" onClick="goNewWin(<?php echo $row['sell_code']; ?>)">
</form>

Nor it works with:

<a href="javascript:goNewWin(<?php echo $row['sell_code']; ?>)">Renovaciones</a>

It's 2:22 am and I can think straight, please help.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongzhong8834
    dongzhong8834 2014-11-28 07:02
    已采纳

    You need to add single quotes to the JavaScript function call:

    <?php
    $sell_code = $row['sell_code'];
    ?>
    <input type="button" value="Renovaciones" onClick="goNewWin('<?php echo $sell_code]; ?>')">
    

    Without it, Javascript will consider your $row['sell_code'] as a javascript keyword.

    You need to pass it as a string (function parameter).

    Reference

    点赞 评论
  • dsa45664
    dsa45664 2014-11-28 06:59

    if $row['sell_code'] is a string the you can use

    $sellCode = $row['sell_code'];
    
    onClick="goNewWin('<?php echo $sellCode; ?>')">
    
    点赞 评论

相关推荐