u jayakodi
jayakodiu@yahoo.com Elements created and added to a web page by scripts are not 'saved' when the
page is saved. Two simple vbs routines presented here can save the dynamically
created elements; the script and other details of the page creating them are
avoided, as may be needed in a graph plottng routine.
The following is the code for a demo page with the two routines.
The first routine init() keeps the count of initial elements (not to be saved) and the second routine sav() will save only the dynamically created elements. Care is taken to save xmlns namespace and style as needed for VML elements.
Remember to invoke init by adding "onload=init()" in the body tag.
-----------
<html>
<body onload=init()>
<input type=button value="Draw Dyn Ele" onclick=dra()>
<input type=button value="Save Dyn Ele" onclick=sav()>
</body>
<script language="vbs">
dim sln
sub init()
sln=document.all.length
end sub
sub sav()
fn=inputbox("Full name of file, with htm extn","JK","c:/1.htm")
set fso=CreateObject("Scripting.FileSystemObject")
set f=fso.CreateTextFile(fn):tn=document.all.length-1
set eel=document.all(0):tt=eel.outerHTML
kk=instr(tt,"<BODY"):jt="<HTML><BODY>":if kk>5 then jt=left(tt,kk-1)+"<BODY>"
for i=sln to tn
set el=document.all(i):tt=el.outerHTML:jt=jt+tt
next
jt=jt+"</BODY></HTML>":f.Write jt:f.Close
end sub
'Sample elements added dynamically
sub dra()
for i=0 to 5
set ele=document.body.appendChild(document.createElement("hr"))
ele.style.position="absolute":ele.style.left=100:ele.style.top=100+i*10
ele.style.width=100:ele.color="#ff0000":ele.size=5
next
set ele=document.body.appendChild(document.createElement("div"))
ele.style.position="absolute":ele.style.left=200
ele.style.top=92:ele.style.width=160:ele.style.padding=5
ele.style.background="#ffff00":ele.style.border="solid 1"
ele.innerText="Demo for saving these dynamically created Elements."
end sub
</script>
</html>
--------