有什么替代location.reload的代码,因为Codepen不允许这样做?

问题描述

我正在一支笔中使用它,但这不起作用

window.addEventListener("resize",function(){
        location.reload();
    }
);

这会导致错误pen.js:223 Uncaught TypeError: location.removedByCodePen is not a function

我尝试引用关于this的帖子,但其中提到的两种解决方案均无效,还会产生其他错误

Refused to display " " in a frame because it set 'x-frame-options' to 'sameorigin'.

解决方法

一个可能可用的选项是返回历史记录,而不是重新加载页面(无法完成)。可以使用history.go(0);,其中0表示要返回的页面数。 history.go(-1);例如返回上一页。