trigger onresize in cross browser compatible manner

后端 未结 2 1090
夕颜
夕颜 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.

提交回复
热议问题