trigger onresize in cross browser compatible manner

后端 未结 2 1089
夕颜
夕颜 2021-01-17 03:20

I would like to trigger the onresize event from my C# code behind. I think this can be done with

Page.clientScript.RegisterScriptBlock(this.getType(), \"id\         


        
相关标签:
2条回答
  • 2021-01-17 04:03

    This should do the trick, DOM Level 2, no idea whether this works in IE6, quirks mode still has no information on this stuff:

    if (document.createEvent) {
        var e = document.createEvent('HTMLEvents');
        e.initEvent('resize', true, false);
        document.body.dispatchEvent(e);
    
    } else if (document.createEventObject) {
        document.body.fireEvent('onresize');
    }
    

    Tested in FF, Chrome and Opera.

    0 讨论(0)
  • 2021-01-17 04:19

    use this $(window).resize(); (tested in FF, chrome, IE8)

    // old answer, fails in FF document.body.onresize()

    0 讨论(0)
提交回复
热议问题