Php 如果(确认){}否则{防止默认值}则阻止默认值不工作Jscript

Php 如果(确认){}否则{防止默认值}则阻止默认值不工作Jscript,php,html,css,jscript,confirm,Php,Html,Css,Jscript,Confirm,我确实让它正常工作了,但是现在我修改了我的html标记,因为我觉得我缺少了求和的东西 代码解释了这一切,但如果没有确认,它不会阻止默认 有谁知道问题出在哪里吗 非常感谢您提供的任何信息 谢谢 <? if (!empty($facebook)) {echo"<a href='#'onClick=\"facebookalert(); MyWindow=window.open('{$facebook}','MyWindow','width=365,height=300'); ret

我确实让它正常工作了,但是现在我修改了我的html标记,因为我觉得我缺少了求和的东西

代码解释了这一切,但如果没有确认,它不会阻止默认

有谁知道问题出在哪里吗

非常感谢您提供的任何信息

谢谢

<?
    if (!empty($facebook)) {echo"<a href='#'onClick=\"facebookalert(); MyWindow=window.open('{$facebook}','MyWindow','width=365,height=300'); return false;\"></a>"; }

?>                                  


function facebookalert(){
if (confirm("You will be Forwarded to the sellers FACEBOOK account to make contact\nYou can return to this website as this window will not close\nThank you")) {
} else {
event.preventDefault();
     return false;
}

};

函数facebookalert(){
如果(确认(“您将被转发到卖家的FACEBOOK帐户进行联系,\n您可以返回此网站,因为此窗口不会关闭,\n谢谢”)){
}否则{
event.preventDefault();
返回false;
}
};
  • 如果要使用event.preventDefault(),则需要将事件对象传递给facebookalert函数

  • event.preventDefault();不是您要用来阻止该窗口打开的

  • 用这个代替

    <?
        if (!empty($facebook)) {echo"<a href='#'onClick=\"if(facebookalert()){window.open('{$facebook}','MyWindow','width=365,height=300'); return false;}\"></a>"; }
    
    ?> 
    
    来自W3C preventDefault()方法停止元素的默认操作

    例如:

    阻止提交按钮提交表单

    阻止链接跟随URL


    它不会中止窗口。请不要执行open。

    非常感谢。这很好…我真的需要好好想想这些东西…很乐意帮忙。如果答案解决了您的问题,您可以接受它。因此,如果(facebookalert(即返回true)){然后使用window.open call进行后续操作}
    function facebookalert(){
    if (confirm("You will be Forwarded to the sellers FACEBOOK account to make contact\nYou can return to this website as this window will not close\nThank you")) {
       return true;
    } else {
         return false;
    }
    
    };