javascript - Call onresize from ASP.NET content page - Stack Overflow

I have a JavaScript method that I need to run on one of my pages, in particular, the onresize event.H

I have a JavaScript method that I need to run on one of my pages, in particular, the onresize event.

However, I don't see how I can set that event from my content page. I wish I could just put it on my master page, but I don't have the need for the method to be called on all pages that use that master page.

Any help would be appreciated.

I have a JavaScript method that I need to run on one of my pages, in particular, the onresize event.

However, I don't see how I can set that event from my content page. I wish I could just put it on my master page, but I don't have the need for the method to be called on all pages that use that master page.

Any help would be appreciated.

Share Improve this question edited Feb 8, 2016 at 14:48 Alexander Elgin 6,9954 gold badges42 silver badges52 bronze badges asked Aug 28, 2008 at 20:24 Kevin GriffinKevin Griffin 2,2574 gold badges25 silver badges27 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

Place the following in your content page:

<script type="text/javascript">

// here is a cross-browser patible way of connecting 
// handlers to events, in case you don't have one
function attachEventHandler(element, eventToHandle, eventHandler) {
    if(element.attachEvent) {
       element.attachEvent(eventToHandle, eventHandler);
    } else if(element.addEventListener) {
       element.addEventListener(eventToHandle.replace("on", ""), eventHandler, false);
    } else {
    element[eventToHandle] = eventHandler;
  }
}

attachEventHandler(window, "onresize", function() {
    // the code you want to run when the browser is resized
});

</script>

That code should give you the basic idea of what you need to do. Hopefully you are using a library that already has code to help you write up event handlers and such.

I had the same problem and have e across this post :

IE Resize Bug Revisited

The above code works but IE has a problem where the onresize is triggered when the body tag changes shape. This blog gives an alternate method which works well

How about use code like the following in your Content Page (C#)?

Page.ClientScript.RegisterStartupScript(this.GetType(), "resizeMyPage", "window.onresize=function(){ resizeMyPage();}", true);

Thus, you could have a resizeMyPage function defined somewhere in the Javascript and it would be run whenever the browser is resized!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744379843a4571372.html

相关推荐

  • javascript - Call onresize from ASP.NET content page - Stack Overflow

    I have a JavaScript method that I need to run on one of my pages, in particular, the onresize event.H

    7天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信