سؤال

js and all works fine in all browsers except IE8. I've next error

Error: 'History.Adapter' is null or not an object

My code:

@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>

and scripts:

   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"

            ));
هل كانت مفيدة؟

المحلول

For correct work in IE 8 you need to place initialization history.js and History.Adapter.bind inside $(document).ready(...) This will work in all browsers...and IE 8 to

@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>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top