admin管理员组文章数量:1402919
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 badges3 Answers
Reset to default 4Place 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!
本文标签: javascriptCall onresize from ASPNET content pageStack Overflow
版权声明:本文标题:javascript - Call onresize from ASP.NET content page - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744379842a2603447.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论