SecurityError: The operation is insecure - window.history.pushState()

前端 未结 9 2127
我寻月下人不归
我寻月下人不归 2020-11-28 08:56

I\'m getting this error in Firefox\'s Console: SecurityError: The operation is insecure and the guilty is HTML5 feature: window.history.pushState()

9条回答
  •  醉话见心
    2020-11-28 09:34

    Make sure you are following the Same Origin Policy. This means same domain, same subdomain, same protocol (http vs https) and same port.

    How does pushState protect against potential content forgeries?

    EDIT: As @robertc aptly pointed out in his comment, some browsers actually implement slightly different security policies when the origin is file:///. Not to mention you can encounter problems when testing locally with file:/// when the page expects it is running from a different origin (and so your pushState assumes production origin scenarios, not localhost scenarios)

提交回复
热议问题