Saturday 24 September 2011

Simple way to refresh just part of a website?

Is there a simple way, maybe using javascript, to change just part of a website. Basically, Im trying to get a top ten box like on this website

http://www.microsoft.com/windowsvista/co鈥?/a>



but rather than images, I'll have text. I'd like to avoid the whole website changing just for a small box of text.

Would an iframe work well or cause problems? What javascript could do this?

Thanks!Simple way to refresh just part of a website?By %26quot;top ten box%26quot;, I'm assuming that you're talking about the 'featured articles' section on the Windows Vista site.



You can use Javascript to manipulate the contents of a web page. This is known as %26quot;DOM Scripting.%26quot;



In order to manipulate a HTML element in Javascript, you first need to %26quot;find%26quot; it. The easiest way to do this is to give your box (which can be a div, a table cell, a span, or whatever) an ID, using the HTML %26quot;id%26quot; attribute.



In your javascript, you can use the function %26quot;document.getElementByID()%26quot; to get a handle to a HTML element/node.



Once you have this handle, you can use the %26quot;innerHTML%26quot; property of the node to set its contents.



So, if you wanted to change the contents of a div with an id of %26quot;foo%26quot;, you would do the following:

var el = document.getElementById('foo');

el.innerHTML = %26quot;New content goes here%26quot;;



I threw together a quick example here:

http://code.jbrisch.org/example.html
  • lock file
  • Duvet cover designers research
  •