Call onresize from an ASP.NET content page

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

However, I do not see how I can set this event on my content page. I would just like to put it on my main page, but I don’t need the method to be called on all pages that use this main page.

Any help would be appreciated.

+3
source share
3 answers

On the content page, place the following:

<script type="text/javascript">

// here is a cross-browser compatible 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>

This code should give you a general idea of ​​what you need to do. I hope you are using a library that already has code that will help you write event handlers, etc.

+4

, (#)?

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

, resizeMyPage, - Javascript, , !

0

I had the same problem and ran into this post:

Changed IE Resize Option

The above code works, but IE has a problem where onresize starts when the body tag changes shape. This blog provides an alternative method that works well.

0
source

Source: https://habr.com/ru/post/1696577/


All Articles