[英]Popup in new window opens in new tab instead
I have a calendar created with php. 我有一个用PHP创建的日历。 In this calendar I have load_id's listed by date.
在这个日历中,我按日期列出了load_id。 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.
我已经尝试将其作为一个函数,但由于我不知道javascript我无法弄清楚如何将load_id传递给url。 If I replace "this.href" with the url in a function it works like a charm.
如果我将“this.href”替换为函数中的url,它就像魅力一样。 But again I don't know how to pass the load id as a variable so that won't work for me.
但是我再次不知道如何将load id作为变量传递,因此对我来说不起作用。 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>\n";
I tried this as well to no avail: 我试过这个也无济于事:
echo "<span class='load_shipped'>
<a onclick='popup(".$load_id.");'>".$load_id."</a><br>
</span>\n";
Javascript: 使用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. 所有这些都是通过'id'而不是真正的load_id。
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. 看起来你遇到了麻烦,因为你使用相同的引号来包装属性
onclick
并定义window.open
调用的参数。 Try using double quotes on the attribute. 尝试在属性上使用双引号。 You'll also need to
return false;
你还需要
return false;
at the end of the onclick
to prevent the link working as normal. 在
onclick
结束时,以防止链接正常工作。
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>\n";
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
. 在上一个有
popup
函数的例子中 - 请注意你需要将id
变量连接到字符串中,如'cal_popup.php?load_id=' + id
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.