Re: Load Body html on button click.
- From: RobG <rgqld@xxxxxxxxxxxx>
- Date: Mon, 29 Sep 2008 19:31:36 -0700 (PDT)
On Sep 30, 6:38 am, Sunny <sunnyluth...@xxxxxxxxx> wrote:
Hi,
Can someone tell me, How to load the Body Html from a text file that
contains javascript.
to Manage my files I am creating an Index Page.
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body onUnload ="WriteCSVFile();">
<script type="text/javascript">
function openWindow(openLink)
{
var abc = openLink;
window.open(abc);
}
function openWindow2()
{
alert(textnode1.value);
var abc = '"' + textnode1.value + '"'
//window.open(eval(abc));
alert(document.body.innerHTML);
}
var textnode1;
var textnode2;
function addRow(content,morecontent)
{
if (!document.getElementsByTagName('mytable')) return;
There are no HTML elements with a tagName of 'mytable', did you mean
to do something like:
if (!document.getElementById) return;
or perhaps:
var tbl;
if ( !document.getElementById ||
!(tbl = document.getElementById('mytable')) {
return;
}
var tbl = document.getElementById('mytable');
tabBody=document.getElementsByTagName("TBODY").item(0);
Since you already have a reference to the table, consider:
var tabBody = tbl.tBodies[0];
var lastRow = tbl.rows.length;
var iteration = lastRow;
//alert(iteration);
row=document.createElement("TR");
cell1 = document.createElement("TD");
cell2 = document.createElement("TD");
textnode1=document.createElement('input');
textnode1.type = 'text';
Please manually wrap code for posting at about 70 characters to
prevent auto-wrapping. Also, indent using 2 or 4 spaces to keep code
compact.
Why are those variables allowed to become global? Keep them local
with var.
textnode1.name = 'txtRow' + iteration;
textnode1.id = 'txtRow' + iteration;
textnode1.size = 80;
var answer = prompt("Enter the URL for Map.","");
textnode1.value =answer;
textnode2=document.createElement('input');
textnode2.type = 'button';
textnode2.name = 'txtRowBut' + iteration;
textnode2.id = 'txtRowBut' + iteration;
textnode2.width = "100"
textnode2.value = "New Map"
cell1.appendChild(textnode1);
cell2.appendChild(textnode2);
row.appendChild(cell1);
row.appendChild(cell2);
tabBody.appendChild(row);
document.all.txtRowBut5.attachEvent("onclick", openWindow2)
document.all is IE proprietary, use getElementById.
attachEvent is IE proprietary, there are plenty of cross-browser
solutions, search the archives for "addEventListener attachEvent".
}
function WriteCSVFile()
{
var ForWriting = 2
var TriStateFalse = 0
var fsObj = new ActiveXObject("Scripting.FileSystemObject")
var newFile = fsObj.OpenTextFile("c:\\abc.txt", ForWriting, true,
TriStateFalse)
More IE specific stuff. There are examples of how to do cross-browser
AJAX in the archives.
newFile.WriteLine(document.body.innerHTML)
newFile.Close()
}
</script>
<div id="plan" style="overflow: auto; width: 780px; height: 780px">
<div id="DateBox">
<script type="text/javascript">
document.write('<b>' + Date());
</script>
</div>
<br/>
Forget the XHTML syntax as you are clearly using HTML.
<br/>
<br/>
<br/><br/>
<table id='mytable' style="font-family:Arial,Helvetica,Sans Serif;font-
size:90%;color:#330066" cellpadding="3" border="2">
<H3><B><U>INDEX</U></B></H3>
Try validating your HTML before doing anything, a table element can
only have table section elements as children, it can't have an h3 as a
child.
<tbody>
<tr><td><input type="TEXT" name="testlabels" style="width:510px"
value=""></td>
<TD><INPUT TYPE="button" VALUE=""
onClick="openWindow(document.getElementById('testlabels').value);">
</td></tr>
<tr><td><input type="TEXT" name="testlabels1" style="width:510px"
value=""></td>
<TD><INPUT TYPE="button" VALUE=""
onClick="openWindow(document.getElementById('testlabels1').value);">
</td></tr>
<tr><td><input type="TEXT" name="testlabels2" style="width:510px"
value=""></td>
<TD><INPUT TYPE="button" VALUE=""
onClick="openWindow(document.getElementById('testlabels2').value);">
</td></tr>
<tr><td><input type="TEXT" name="testlabels3" style="width:510px"
value=""></td>
<TD><INPUT TYPE="button" VALUE=""
onClick="openWindow(document.getElementById('testlabels3').value);">
</td></tr>
</tbody>
</table>
</form>
Where is the opening tag for the form?
<INPUT TYPE="button" VALUE="Add Map" onClick="addRow();return false;">
The "return false" here does nothing useful.
<br/>
</div>
</body>
</html>
*****************************************************************************************************
At the Body unload I am taking the Body InnerHtml & saving it in a
File. abc.txt. As I am adding the Links on the fly to the table, so I
need some place to save them. I want that when Next time, I open this
webpage, It should automatically, read all the script that I saved to
abc.txt file. Or Is there a better way to add the contents & save it.
The innerHTML property is proprietary, there is no public standard for
its use. Different browsers have implemented it differently, so it is
inconsistent. I better idea would be to serialise the data you want
to keep, then parse it back into the document when it is re-loaded.
Have a look at TiddlyWiki to see how they've done it.
<URL: http://www.tiddlywiki.com/ >
--
Rob
.
- Follow-Ups:
- Re: Load Body html on button click.
- From: Sunny
- Re: Load Body html on button click.
- References:
- Load Body html on button click.
- From: Sunny
- Load Body html on button click.
- Prev by Date: Re: Javascript about to be disabled event
- Next by Date: Re: "Access is denied" in IE on node.focus()
- Previous by thread: Re: Load Body html on button click.
- Next by thread: Re: Load Body html on button click.
- Index(es):