开发者

How to refresh just a specific portion of an HTML page?

开发者 https://www.devze.com 2023-02-27 11:18 出处:网络
I have one HTML file containing several <div> elements. I want to refresh just part of the page using either JavaScript or C#.Can someone help?

I have one HTML file containing several <div> elements. I want to refresh just part of the page using either JavaScript or C#. Can someone help?

I am trying to do it this way:

document.location.reload(开发者_开发问答document.getElementById("contentdiv"));

It reloads the whole page. I wish to reload contentdiv. If contentdiv is at the middle of the page then it should load only that part.

Thank you.


You could move the contents of everything you want reloaded into an external file, and either use the <iframe> tag and only refresh that frame, or you could use JavaScript and refresh the div with Ajax.

Ajax isn't that simple to explain in a short answer, but you can find plenty of information on it here: http://www.w3schools.com/Ajax/ajax_example.asp or if you use a framework like jQuery ajax is much easier.

iFrames can be implemented (on mypage.html, for example) like so: <iframe src='mypagecontent.html'></iframe> and in mypagecontent.html you could use <script type='text/javascript'>window.location.reload();</script> to refresh the frame.

Not sure if this is what you're looking for, but hope it helps somewhat.


What ASP.NET Framework are you using? If you are using Web Forms, look into UpdatePanel

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号