PHP 与AJAX onclick 问题
我需要一些帮助才能让它发挥作用。它有效,但我必须单击“喜欢”按钮的侧面。我希望它在单击 iframe 时注册单击。我也尝试在 iframe 中设置 onclick,但这也不起作用。
这是我在页面顶部的脚本:
<script type="text/javascript">
function updateLikes(id) {
var ajax;
// Code for IE7+, Firefox, Chrome, Opera, Safari
if (window.XMLHttpRequest) {
ajax=new XMLHttpRequest();
} else { // code for IE6, IE5
ajax=new ActiveXObject("Microsoft.XMLHTTP");
}
ajax.onreadystatechange=function()
{
if (ajax.readyState==4 && ajax.status==200)
{
document.getElementById("images0").innerHTML=ajax.responseText;
}
}
ajax.open("POST","update_likes.php", false);
ajax.send("image_id=" + id);
}
</script>
然后是我回显的内容:
echo '
<div align="center" class="images" id="images'.$i.'">
<a class="image" border="0" href="p.php?id='.$row['id'].'">
<img class="img" src="'.$row['path'].'" alt="image" />
</a>
<div class="meta" style="padding-bottom:5px;">Lastet opp av <div style="color:#47a09f; display:inline;"><a href="user.php?user='.$row['uploader'].'" style="color:#47a09f;">'.$row['uploader'].'</a></div></div>
<div id="likebutton" class="faceLike" align="center" onClick="updateLikes(' . "'" . $row['id'] . "'" . ');"><iframe src="//www.facebook.com/plugins/like.php?app_id=144501772249167&href=http://www.puffys.net/p.php?id='.$row['id'].'&send=true&layout=button_count&width=0&show_faces=false&action=like&colorscheme=light&font=tahoma&height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:21px;" allowTransparency="true"></iframe></div>
</div>
';
我的问题是 facebook 按钮。当我单击它时,我希望它使用 onclick 注册单击,以便将其插入到我的数据库中。但这种情况并没有发生。仅当我单击“喜欢”按钮的侧面时。
提前谢谢。
I need some help to get this to work. It works, but i have to click at the side of the like button. I want it to register the click when the iframe is clicked. I tried setting the onclick in the iframe too, but that didn't work either.
This is my script in the top of the page:
<script type="text/javascript">
function updateLikes(id) {
var ajax;
// Code for IE7+, Firefox, Chrome, Opera, Safari
if (window.XMLHttpRequest) {
ajax=new XMLHttpRequest();
} else { // code for IE6, IE5
ajax=new ActiveXObject("Microsoft.XMLHTTP");
}
ajax.onreadystatechange=function()
{
if (ajax.readyState==4 && ajax.status==200)
{
document.getElementById("images0").innerHTML=ajax.responseText;
}
}
ajax.open("POST","update_likes.php", false);
ajax.send("image_id=" + id);
}
</script>
Then there is what im echo'ing out:
echo '
<div align="center" class="images" id="images'.$i.'">
<a class="image" border="0" href="p.php?id='.$row['id'].'">
<img class="img" src="'.$row['path'].'" alt="image" />
</a>
<div class="meta" style="padding-bottom:5px;">Lastet opp av <div style="color:#47a09f; display:inline;"><a href="user.php?user='.$row['uploader'].'" style="color:#47a09f;">'.$row['uploader'].'</a></div></div>
<div id="likebutton" class="faceLike" align="center" onClick="updateLikes(' . "'" . $row['id'] . "'" . ');"><iframe src="//www.facebook.com/plugins/like.php?app_id=144501772249167&href=http://www.puffys.net/p.php?id='.$row['id'].'&send=true&layout=button_count&width=0&show_faces=false&action=like&colorscheme=light&font=tahoma&height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:21px;" allowTransparency="true"></iframe></div>
</div>
';
My problem is the facebook button. When i click it, i want it to register the click with onclick so it's inserted to my database. But that does not happen. Only if i click at the side of the like button.
Thx in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将无法捕获 DIV 的单击事件,因为 IFRAME 中的文档 ONCLICK 事件先于它。
此外,您将无法捕获 IFRAME 的点击事件,因为它被目标页面覆盖。
您需要使用 Facebook API,如下所述:Facebook“赞”按钮回调
You won't be able to capture the click event of the DIV, as the document ONCLICK event from the IFRAME precedes it.
Also, you won't be able to capture the click event of the IFRAME, as it is overriden by the destination page.
You need to use the Facebook API, as described here: Facebook "Like" button callback