history.pushState交叉原点

时间:2018-08-06 17:40:08

标签: javascript cors pushstate

我正在使用ASP.NET MVC应用程序,并且View中的history.pushState操作存在问题。我使用以下代码简化了方案:

@section Scripts
{
    <script type="text/javascript">
        history.pushState(null, null, 'https://cors-test.appspot.com/test');
    </script>
}

据我了解,如果允许CORS并且https://cors-test.appspot.com/test允许CORS,则应该允许该操作。无论如何,如果我尝试此代码,则会出现以下错误:

Uncaught DOMException: Failed to execute 'pushState' on 'History': A history state object with URL 'https://cors-test.appspot.com/test' cannot be created in a document with origin 'http://localhost:63397' and URL 'http://localhost:63397/game/pushhistory'.
    at http://localhost:63397/game/pushhistory:44:17

如果我尝试将州推入历史,并保持原点不变,那就没问题了。

谢谢

stefano。

0 个答案:

没有答案