dos8410 2014-05-20 03:27
浏览 26
已采纳

新窗口中的弹出窗口将在新选项卡中打开

I have a calendar created with php. In this calendar I have load_id's listed by date. I made a popup to show more data for each load. I want it to show as a popup not in a new tab. I have tried doing it as a function but as I don't know javascript I could not figure out how to pass the load_id to the url. If I replace "this.href" with the url in a function it works like a charm. But again I don't know how to pass the load id as a variable so that won't work for me. If someone could point out where I made my mistake passing the variable I would be much obliged!

This is what I have now:

echo "<span class='load_shipped'>
<a href='cal_popup.php?load_id=".$load_id."'
onclick='window.open(this.href, '_blank','left=100,top=100,width=500,height=500,toolbar=1,resizable=0');'>
".$load_id."
</a>
<br>
</span>
";

I tried this as well to no avail:

echo "<span class='load_shipped'>
<a onclick='popup(".$load_id.");'>".$load_id."</a><br>
</span>
";

Javascript:

<script>
    function popup(id){
        window.open('cal_popup.php?load_id=id', '_blank','left=100, top=100,width=500,height=500,toolbar=1,resizable=0');
    }
</script>

All this did though was pass 'id' instead of the real load_id.

  • 写回答

1条回答 默认 最新

  • douzhankui0758 2014-05-20 03:38
    关注

    Seems like you're having trouble because you're using the same quotes to wrap the attribute onclick and to define the parameters of the window.open call. Try using double quotes on the attribute. You'll also need to return false; at the end of the onclick to prevent the link working as normal.

    echo "<span class='load_shipped'>
        <a href='cal_popup.php?load_id=".$load_id."'
        onclick=\"window.open(this.href, '_blank','left=100,top=100,width=500,height=500,toolbar=1,resizable=0');return false;\">
        ".$load_id."
        </a>
        <br>
    </span>
    ";
    

    In your last example where you have the function popup - please note that you need to concatenate the id variable into the string like 'cal_popup.php?load_id=' + id.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应