错误:'History.Adapter'为null或不是对象

时间:2013-11-21 07:41:40

标签: javascript internet-explorer history.js

js和所有浏览器都可以正常工作,除了IE8。 我有下一个错误

  

错误:'History.Adapter'为null或不是对象

我的代码:

@Scripts.Render("~/bundles/history")
<script type="text/javascript">

    var History = window.History;  
    $(document).ready(function () {           
    change(1, '#catalog');        

    History.Adapter.bind(window, 'statechange', function () {
        try {
            var State = History.getState();
            $('#Products').load(State.url);
        } catch (e) {

        }    
    });

    function change(id, ItemMenu) {   
        var url = $('#' + id).val();
        try
        {        
            History.pushState({}, null, url);
        }
        catch(e)
        {
        }                

    }
</script>

和脚本:

   bundles.Add(new ScriptBundle("~/bundles/history").Include(
            "~/Scripts/History/history.adapter.jquery.js",
            "~/Scripts/History/history.html4.js",
            "~/Scripts/History/history.js",
            "~/Scripts/History/json2.js"

            ));

1 个答案:

答案 0 :(得分:0)

要在IE 8中正确工作,您需要将初始化history.js和History.Adapter.bind放在$(document).ready(...)中 这适用于所有浏览器......和IE 8到

@Scripts.Render("~/bundles/history")
<script type="text/javascript"> 
    $(document).ready(function () {
        var History = window.History;

        History.Adapter.bind(window, 'statechange', function () {
            try {
                var State = History.getState();
                $('#Products').load(State.url);
            } catch (e) {

            }
        });
    });


    function change(id, ItemMenu) {  
        var url = $('#' + id).val();
        try
        {        
            History.pushState({}, null, url);
        }
        catch(e)
        {
        }                

    }
</script>