按下javascript警告确定时刷新页面

时间:2013-08-05 14:14:54

标签: php refresh

    function myFunction() 
    {
        var first = confirmDelete(); 
        var second = refreshPage();
        return (first && second);
    }

    function confirmDelete()
    {
        var agree= confirm("confirm?");
        if (agree == true)
            {
            $result = array();
            $result[0] = ('<?php    
                if (isset($_POST['check']))
                {
                    if ($queryType == "apps")
                    {
                        $deletePath = "delete/";
                        include $deletePath.'deleteLastApp.php';
                        include $deletePath.'deleteApp.php';
                    }
                }
                ?>');
            $result[1] = true;
            return $result;
            }
        else
            {
            return false;
            }
    }

    function refreshPage()
    {
        window.location.reload()
    }

除了refreshPage函数之外,所有这些代码都可以正常工作。当警报“确认?”出现并按下确定按钮,我希望页面重新加载。只有取消按钮才会重新加载页面。如何修复此问题,以便只有ok按钮重新加载页面?

1 个答案:

答案 0 :(得分:2)

您可以尝试将refreshPage()功能更改为以下其中一项:

function refreshPage()
{
    history.go(0);
}

或:

function refreshPage()
{
    document.reload()
}

另一个可能的问题可能是您没有在正确的位置调用refreshPage()

修改

试试这个:

function refreshPage()
{
    window.location.reload()
}

function myFunction() 
{
    var first = confirmDelete(); 
    var second = refreshPage();
    return (first && second);
}

function confirmDelete()
{
    var agree= confirm("confirm?");
    if (agree == true)
        {
        $result = array();
        $result[0] = ('<?php    
            if (isset($_POST['check']))
            {
                if ($queryType == "apps")
                {
                    $deletePath = "delete/";
                    include $deletePath.'deleteLastApp.php';
                    include $deletePath.'deleteApp.php';
                }
            }
            ?>');
        $result[1] = true;
        return $result;
        refreshPage();
        }
    else
        {
        return false;
        }
}

请注意,我将refreshPage()块的位置更改为页面顶部,并在return $result行下添加了对该功能的调用。

制作完整的代码,看看它是否有效!