Sunday, January 3, 2010

iFrame or not to Frame?

Once a web developer touches iframe, it's hard not to in the future.

Web developers can get addicted to iframe as it is a versatile feature.

One can easily create an iframe using this syntax:


<iframe src="test.asp" width=100 height=100 scrolling=auto frameborder=0 align=right id="iframe1"></iframe>



This creates an iframe of 100x100 in size that calls to main.asp. The 100x100 area is reserved for this test.asp.

The purpose of iframe is to separate the loading of various HTML files. Usually, there is a javascript to control the iframe so that the loading of the iframe doesn't require to reload the entire main page or the page that calls the iframe.

Here's the javascript code to do the job easily:


function reloadiframe() {
document.getElementById("iframe1").src='test.asp';
}



or you can also change the link of the iframe:


function changeiframe(framename) {
document.getElementById("iframe1").src=framename+'.html';
}



To call the javascript functions, one call put codes like
"javascript:changeiframe('test2')"
or
"javascript:reloadiframe()"
in the anchor (<a>) or using onclick.


Hope you like it. This is my 3rd posting and at least can write for 3 days consecutively. I doubt I can continue forever but discipline is very important in making anything successful.

No comments:

Post a Comment