最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - IE11 window.history.pushState "Object doesn't support property or method 'pushState&#3

programmeradmin4浏览0评论

I have this simple html code below. It works as expected (appending ?SomeParam to the url) in my development environment (Visual Studio 2010) in both Chrome and IE11. When I put this in an htm file on the web server, it works in Chrome, but in IE11 it gives "Object doesn't support property or method 'pushState'. I've searched this thoroughly and can only find that pushState is not supported in IE versions <= 9.0 but should be supported in IE10 and IE11.
Does anyone have any ideas?

<script language="javascript" type="text/javascript">
    function test1() {
        try {
            window.history.pushState("abc", "", "/?SomeParam");
        }
        catch (err) {
            alert(err.message);
        }
    }
</script>
<button id="button1" onclick="test1()">Test</button>

I have this simple html code below. It works as expected (appending ?SomeParam to the url) in my development environment (Visual Studio 2010) in both Chrome and IE11. When I put this in an htm file on the web server, it works in Chrome, but in IE11 it gives "Object doesn't support property or method 'pushState'. I've searched this thoroughly and can only find that pushState is not supported in IE versions <= 9.0 but should be supported in IE10 and IE11.
Does anyone have any ideas?

<script language="javascript" type="text/javascript">
    function test1() {
        try {
            window.history.pushState("abc", "", "/?SomeParam");
        }
        catch (err) {
            alert(err.message);
        }
    }
</script>
<button id="button1" onclick="test1()">Test</button>
Share Improve this question asked Apr 11, 2015 at 14:35 tonitoni 1331 silver badge11 bronze badges 1
  • history is a single DOM object in IE. Try history.pushState. – Deadooshka Commented Apr 11, 2015 at 16:47
Add a ment  | 

1 Answer 1

Reset to default 13

Try adding the following meta tag to your page, if you haven't done so already:

<meta http-equiv="x-ua-patible" content="IE=edge">

Ensure also that this is the first meta tag on the page.

Are you running this application on an intranet? If so, IE11 may decide to emulate an older version of IE (check this using F12 Developer Tools). The above meta tag should stop IE from doing this and force it to render the page in IE11 mode.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论