【问题标题】:history.js state not working in IE9history.js 状态在 IE9 中不起作用
【发布时间】:2012-11-08 23:21:51
【问题描述】:

我正在使用history.js 脚本来管理 HTML5 历史状态更改。我的代码在最新版本的 Chrome 和 Firefox 中运行良好,但无法在 IE9 中运行。我已经尝试过可以从 github 站点获得的 history.js 和 history.iegte8.min.js 脚本。

我选择这个脚本的原因是因为它遵循与正确的 HTML5 API 相同的语法,这意味着当用户最终进入 IE10 时所做的更改最少。

这是代码。

    <!-- Placed at the end of the document so the pages load faster -->
<script src="js/jquery-1.8.2.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="js/history.iegte8.min.js"></script>

<script type="text/javascript">

    $(function() {

        $(window).bind('popstate', function( e ) {

            var historyState = history.state;
            if ( historyState ) {
                loadContent(historyState.link)
            } else {
                // Open Business Unit Reporting folder
                $('#item-2').prop('checked',true);
            }
        });         

        $('li a').click(function(e) {
            var latestLink = '<li>' + getLabelHierarchy(this) + '<a href="'+$(this).attr('href')+'">'+$(this).html()+'</a></li>';
            var historyList = latestLink + $('#historyList').html();
            history.replaceState({link: historyList}, null, null);              
        });

        $(window).trigger( "popstate" );

    });

    function getLabelHierarchy(node) {
                << code omitted >>
    }

    function loadContent(links) {
        $('#historyList').append(links);
    }


</script>

有人在 IE9 中使用过这个脚本吗?
非常感谢任何帮助。

【问题讨论】:

  • 仅供参考:您应该使用的 jQuery 版本 on,而不是 bind。它不会做任何事情来修复你的错误。
  • 库的开发者试图找出 hashchanged 和 popstate 的事件处理程序是什么,并自己提升它们。在他关于github.com/devote/HTML5-History-API 的示例中,包含的顺序是history.js 然后是jquery.js。试试那个顺序。

标签: jquery html internet-explorer-9 history.js


【解决方案1】:

当你使用 History js 时,它是大写的 H,而不是小写的 h,当你使用 history 时,你使用的是 window.history,而不是 history.js History 对象。

你需要使用getState()

var historyState = History.getState();

您还需要在引用它的其他地方使用历史记录。阅读 History.js 的自述文件。

【讨论】:

  • 不幸的是没有骰子。我认为您指的是 History.js,而我使用的是 [HTML5-History-API] (github.com/devote/HTML5-History-API) 我尝试使用的脚本的好处是它遵循 HTML5 历史语法。检查它可能适用于 IE8 的源代码,但看起来它希望 IE9 支持它不支持的 History API。我可能需要在一天结束时使用 History.js。
猜你喜欢
  • 1970-01-01
  • 2012-07-06
  • 2012-10-02
  • 1970-01-01
  • 2012-03-05
  • 2018-04-29
  • 2012-02-09
  • 2012-08-02
  • 2014-05-04
相关资源
最近更新 更多