Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder GSimpson's Avatar
    Join Date
    Aug 2006
    Location
    New Zealand
    Posts
    268
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Local Popup for web builder

    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.
    The internet is my Sandbox, and notepad is my Spade n' Bucket.

  • #2
    Senior Coder coothead's Avatar
    Join Date
    Jan 2004
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,736
    Thanks
    0
    Thanked 241 Times in 236 Posts
    Hi there GSimpson,

    try it like this...
    Code:
    
    <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
    Last edited by coothead; 09-01-2006 at 02:09 PM.

  • #3
    Regular Coder GSimpson's Avatar
    Join Date
    Aug 2006
    Location
    New Zealand
    Posts
    268
    Thanks
    9
    Thanked 0 Times in 0 Posts
    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!
    The internet is my Sandbox, and notepad is my Spade n' Bucket.

  • #4
    Senior Coder coothead's Avatar
    Join Date
    Jan 2004
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,736
    Thanks
    0
    Thanked 241 Times in 236 Posts
    Hi there GSimpson,

    Sorry but I misunderstood your requirements.
    I thought that you wanted to preview the file rather than the textarea contents.
    So try this...
    Code:
    <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

  • #5
    Regular Coder GSimpson's Avatar
    Join Date
    Aug 2006
    Location
    New Zealand
    Posts
    268
    Thanks
    9
    Thanked 0 Times in 0 Posts
    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!
    The internet is my Sandbox, and notepad is my Spade n' Bucket.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •