...

View Full Version : Local Popup for web builder



GSimpson
09-01-2006, 03:21 AM
I have built something that allows me to choose a filename, filetype and the content of the file then save with the filename and type to the same directory.
It is all in my single .hta file. so I now want to add a preview button to it.

Here is my script, I put in the preview button already with a function named preview().



<HTML>
<HEAD>
<title>Web Builder</title>
<STYLE TYPE="TEXT/CSS">
div.one
{
border-style: solid;
border-width: 1px;
border-color: #000000;
background-color: #c9c9c9;
text-align: center;
}
</STYLE>
<SCRIPT TYPE="text/javascript">



function preview(){

}


fso = new ActiveXObject("Scripting.FileSystemObject");

function makeFile()
{
var TristateFalse = 0;
var ForWriting = 2;
var filename = document.info.fname.value;
var extension = document.info.exten.value;
thepage = ""+filename+extension;
thecontent = document.info.content.value;
fso.CreateTextFile(thepage);
a = fso.GetFile(thepage);
b = a.OpenAsTextStream(ForWriting, TristateFalse);
b.Write(thecontent);
b.Close();
c = fso.GetFile(thepage);
alert(filename+extension+' Was Successfully Created!');
return false;
}

</SCRIPT>
</HEAD>
<BODY>
<DIV CLASS="one">
<FONT FACE="VERDANA" SIZE="7" COLOR="#000000"><P ALIGN="center">
<BR>
Web Builder<BR>
<FONT SIZE=2>
This application is &copyCopyright Ambitous Spirit, 2006-2007.<BR><BR>
<FONT SIZE="3">
Enter The Information That The Application Requires:<BR>
<form action="#" method="post" onsubmit="return makeFile()" name="info">
<input type="text" value="Filename" name="fname">
<select name="exten">
<option value=".html">Choose File Type</option>
<option value=".html">.html</option>
<option value=".htm">.htm</option>
<option value=".xhtml">.xhtml</option>
<option value=".xml">.xml</option>
</select><br>
<textarea name="content" rows="15" cols="80">
Instructions:
1. Choose a name for this file.
2. Choose a file type. -- if none selected then it will save as .html --
3. Enter all content here.
4. View in preview mode.
5. Save to local directory.
</textarea>

<BR>
<input type="button" value="Preview" onclick="preview()"> <input type="submit" value="Save"><BR><BR>
</form>
</DIV>
<BR>
<DIV CLASS="one">
Note. This application will only make files for windows operating systems.<BR><BR>
Note. All created files are created in the same directoy as the Web Builder.
</DIV><BR>
<DIV CLASS="one"><FONT SIZE=1>
Application History:<BR>
This applications scripting was done by _Aerospace_Eng_ of the CodingForums. All additional scripting was done

by GSimpson of Ambitous Spirit.<BR><BR>This application was released by Ambitous Spirit.
</DIV>
</BODY>
</HTML>

Thanks in advance,
GSimpson.

coothead
09-01-2006, 12:09 PM
Hi there GSimpson,

try it like this...


<script type="text/javascript">

var filename;
var extension;
var mywindow;
var features='width=500,height=400';

function preview() {
if(filename==null) {
alert('you have not created a file to view yet!!!');
return;
}
if(mywindow) {
mywindow.close();
}
url='C:/Documents and Settings/user name/Desktop/'+filename+extension;
mywindow=window.open(url,'',features);
mywindow.focus();
}


fso = new ActiveXObject("Scripting.FileSystemObject");

function makeFile()
{
var TristateFalse = 0;
var ForWriting = 2;
filename = document.info.fname.value;
extension = document.info.exten.value;
thepage = ""+filename+extension;
thecontent = document.info.content.value;
fso.CreateTextFile(thepage);
a = fso.GetFile(thepage);
b = a.OpenAsTextStream(ForWriting, TristateFalse);
b.Write(thecontent);
b.Close();
c = fso.GetFile(thepage);
alert(filename+extension+' Was Successfully Created!');
return false;
}

</script>

...just replace user name with the appropriate name, and adjust the features variable to suit your requirements. ;)
coothead

GSimpson
09-02-2006, 06:59 AM
Thanks for that but I have to problems with that, what if they haven't saved there file yet and they want to preview it? and also is there anyway I can get rid of the username thing because then it can only be used on pcs that have that username, and I don't want to complicate my app with more forms or prompts! thanks in advance again!

coothead
09-02-2006, 07:42 AM
Hi there GSimpson,

Sorry but I misunderstood your requirements. :o :o
I thought that you wanted to preview the file rather than the textarea contents.
So try this...

<script type="text/javascript">

var mywindow;
var features='width=500,height=400';

function preview() {

if(mywindow) {
mywindow.close();
}
mywindow=window.open('','',features);
mywindow.document.write(document.info.content.value);
mywindow.document.close();
mywindow.focus();
}

fso=new ActiveXObject("Scripting.FileSystemObject");

function makeFile() {
TristateFalse = 0;
ForWriting = 2;
filename=document.info.fname.value;
extension=document.info.exten.value;
thepage=""+filename+extension;
thecontent=document.info.content.value;
fso.CreateTextFile(thepage);
a=fso.GetFile(thepage);
b=a.OpenAsTextStream(ForWriting, TristateFalse);
b.Write(thecontent);
b.Close();
c=fso.GetFile(thepage);
alert(filename+extension+' Was Successfully Created!');
return false;
}
</script>
coothead

GSimpson
09-04-2006, 06:15 AM
Thanks man, this is a big help to me! also this web builder is a faster way to build pages! type name, choose type, build content save, preview! one easy application!

Is there a code so that I can reopen a file? because then I'll have a notepad for web building!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum