JavaScript Location.replace 不起作用

javascript location.replace doesn't work

本文关键字:不起作用 replace Location JavaScript      更新时间:2023-09-26

我有这个代码:

<?php
include 'theme.php';
css();
if($_POST['wget-send'])
    {
    $formdir=$_POST['dir'];
    $formlink=$_POST['link'];
    $filelink = fopen('/root/wget/wget-download-link.txt',a);
    $filedir = fopen('/root/wget/wget-dir.txt',w);
    fwrite($filedir, $formdir);
    /*
    fwrite($filelink, $formlink."'n");
    exec('touch /root/wget/wget-download-link.txt',$out);
    exec('echo "'.$dir.'" > /root/wget/wget-dir.txt',$out);
        */
    exec('echo "'.$formlink.'" > /root/wget/wget-download-link.txt');
    exit();
    }
echo "<form action='"".$PHP_SELF."'" method='"post'" id='"WgetForm'">";
echo "Download directory:<br><input type='"text'" name='"dir'" size='"15'" value='"/mnt/usb/'"/><br>";
echo '<br>Download link:';
echo ("<textarea name='"link'" rows='"13'" cols='"62'"></textarea><br><br>");
echo '<input type="submit" onclick="LinkAdded()" name="wget-send" value="Send" id="WgetID"/>';
echo "</form></div>";
echo <<<HTML
<script type="text/javascript">
function LinkAdded()
    {
            alert("Link has been sucessfully sent to wget, it'll be downloaded soon, check the wget log for the download progress");
            location.replace("wget_log.php");
    }
</script>
HTML;
foot();
echo '
</div>
</body>
</div>
</html>';
?>

alert部分有效,它给了我一个弹出窗口,但在弹出窗口之后,它只是给了我一个空白页。如何使location.replace("wget_log.php");工作?

stackoverflow一直告诉我,我应该在我的帖子中添加更多细节,但我认为这就是我能提供的所有细节。

您需要

通过从单击处理程序返回false来阻止提交表单的默认操作

echo '<input type="submit" onclick="LinkAdded(); return false;" name="wget-send" value="Send" id="WgetID"/>';