0

有没有办法通过php清空localStorage(在html5中定义)?

我需要这样的东西:

<script type="text/javascript">
    window.localStorage.clear();
</script>

<?php header('Location: '.$adress); ?>

但不幸的是,它不可能在标题之前调用 javascript :(

知道如何解决这个问题吗?

4

1 回答 1

1

否:您还需要在 Javascript 中进行重定向:

<script type="text/javascript">
    window.localStorage.clear();
    window.location = "<?= $adress ?>";
</script>

您只能localstorage使用 Javascript 进行操作,如果您Location使用 PHP 发送标头,则不会执行 Javascript。

于 2012-07-08T18:32:25.673 回答