Results 1 to 9 of 9

Thread: How to save with Javascript?

  1. #1
    Join Date
    Sep 2010
    Location
    Hi Stalker.
    Posts
    148
    Thanks
    16
    Thanked 3 Times in 3 Posts

    Default How to save with Javascript?

    Hello. Long time no see. So I have made a JavaScript Tryit Editor clone... But, I would like to have some code to save a file with the code they added onto my server made into a page. A .HTML page. I would like for it only to be in HTML or JavaScript, even though I'm over 100% sure HTML can't do it alone, I may be wrong. I've also been making a PHP, ASP, Perl, Ruby, and lots more Tryit Editors. So, once I have this code, I could just use Javascript on each of them instead of having to find a lines of code for each different Scripting language. Is this possible to save a webpage onto my server with JavaScript?
    Last edited by [Nicolas]; 11-02-2010 at 11:46 PM.

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Read this all the way to the bottom: http://www.tek-tips.com/viewthread.c...1476631&page=1

    Good luck!
    Jeremy | jfein.net

  3. #3
    Join Date
    Sep 2010
    Location
    Hi Stalker.
    Posts
    148
    Thanks
    16
    Thanked 3 Times in 3 Posts

    Default

    Already working! Thanks!

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    No problem, I'm glad to help.

    Here on DD, we like to keep things organized. In an effort to do so, you have the option to set a thread to resolved when an issue is fixed. To make the status of the thread resolved:
    1. Go to your first post
    2. Edit your first post
    3. Click "Go Advanced"
    4. In the dropdown next to the title, select "RESOLVED"
    Jeremy | jfein.net

  5. #5
    Join Date
    Sep 2010
    Location
    Hi Stalker.
    Posts
    148
    Thanks
    16
    Thanked 3 Times in 3 Posts

    Default

    Cancel, it's not working with this:
    Code:
    <html>
    <head>
    <script type="text/javascript">
    function ChangeStyle()
    {
    document.getElementById("p1").style.fontFamily="Arial";
    document.getElementById("p1").style.fontSize="larger";
    }
    </script>
    <script type="text/javascript">
    function loc()
    {
    window.location = location
    }
    </script>
    <script type="text/javascript">
    function show()
    {
    document.write(' <html><head>
    document.write('<script type=text/javascript>
    function go_saveas() {
        if (!!window.ActiveXObject) {
            document.execCommand('SaveAs');
        } else if (!!window.netscape) {
            var r=document.createRange();
            r.setStartBefore(document.getElementsByTagName('head')[0]);
            var oscript=r.createContextualFragment('<script id="scriptid" type='application/x-javascript' src="chrome://global/content/contentAreaUtils.js'><\/script>');
            document.body.appendChild(oscript);
            r=null;
            try {
                netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
                saveDocument(document);
            } catch (e) {
                
            } finally {
                var oscript=document.getElementById('scriptid');    //re-defined
                oscript.parentNode.removeChild(oscript);
            }
        }
    } ')
    </script><title>'+html.title.value+'</title>'+html.head.value+'</head> ')
    document.write(' <body><form>'+html.htmlcode.value+'</form><br /><br /> ')
    document.write(' <button onclick=go_saveas();return false>Save This Page</button> </body></html> ')
    }
    </script>
    <script type="text/javascript">
    function asp()
    {
    window.location='download.asp'
    }
    </script>
    <script type="text/javascript">
    function php()
    {
    window.location='download.php'
    }
    </script>
    <script type="text/javascript">
    function cfm()
    {
    window.location='download.cfm'
    }
    </script>
    <script type="text/javascript">
    function perl()
    {
    window.location='download.pl'
    }
    </script>
    <script type="text/javascript">
    function ruby()
    {
    window.location='download.rb'
    }
    </script>
    <script type="text/javascript">
    function htm()
    {
    window.location='download.html'
    }
    </script>
    <script language="javascript" type="text/javascript">
    <!--
    // JavaScript Document
    function set_cookie(name,value,days) {
        if (days) {
            var date = new Date();
            date.setTime(date.getTime()+(days*24*60*60*1000));
            var expires = "; expires="+date.toGMTString();
        }
        else var expires = "";
        document.cookie = name+"="+value+expires+"; path=/";
    }
    
    function get_cookie(name) {
        var name_eq = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++) {
            var c = ca[i];
            while (c.charAt(0)==' ') c = c.substring(1,c.length);
            if (c.indexOf(name_eq) == 0) return c.substring(name_eq.length,c.length);
        }
        return null;
    }
    
    
    if(get_cookie("page_size") != null){  
        document.write('<style>');
        document.write('body{');
        document.write('font-size:'+ get_cookie("page_size") + 'em');
        document.write('}');
        document.write('</style>')
    }else{
        document.write('<style>');
        document.write('body{');
        document.write('font-size: 1em');
        document.write('}');
        document.write('</style>')  
    }
       
    
    -->
    </script>
    </head>
    <body bgcolor="78BAC4" id="p1" name="p2">
    <form action="#" name="html">
    Title of site:<br /> <input type="text" name="title" /><br />
    Code for the HEAD tag:<br /> <textarea name="head" rows="8" cols="50" style="background-color: lime; font-weight: bold; color: white;"></textarea><br />
    Code inside the page:<br /> <textarea name="htmlcode" rows="8" cols="50" style="background-color: #CCCCCC; font-weight: bold;"><!-- Tryit Editor by N+S Studios (C) 
    
    All Rights Reserved --></textarea>
    <input type="hidden" name="id" value="092874389540983509">
    <input type="image" src="codeit.bmp" onclick="show()" />&nbsp;<input type="image" src="reset.bmp" onclick="loc()" />
    </form>
    <select>
    <option onclick="asp()">Tryit Editor ASP</option>
    <option onclick="php()">Tryit Editor PHP</option>
    <option onclick="perl()">Tryit Editor Perl</option>
    <option onclick="ruby()">Tryit Editor Ruby</option>
    <option onclick="cfm()">Tryit Editor Cold Fusion</option>
    <option onclick="htm()">Tryit Editor HTML</option>
    </select>
    
    
    <br>
    
    <div id=sampleLayer style="position:absolute; top:20px; left:15px; width:100px; height:40px; background:#EEEEEE; border: 1px solid #919191; font-family:Verdana; 
    
    font-size:8pt">Welcome. Try out the <font color="#0000FF"><u><b onclick="window.location='demo.htm'">Color Picker</b></u></font></div>
    
    <script language=JavaScript>
    var posX, posY;
    var ie    = document.all?1:0;
    var ns    = document.layers?1:0;
    var dom   = document.getElementById?1:0;
    var dhtml = new svetLayer("sampleLayer");
    var path  = new 
    
    Array(29,33,29,33,29,33,29,33,29,33,29,33,29,33,29,33,29,33,29,33,29,33,29,33,29,33,29,33,29,33,29,33,29,33,29,33,29,33,29,33,29,33,32,35,34,36,36,38,36,38,39,38,43,
    
    39,43,39,49,42,58,44,65,47,65,47,71,50,80,54,80,54,92,60,106,64,120,70,120,70,132,76,149,80,168,87,185,95,205,106,225,117,225,117,247,128,267,141,267,141,286,152,
    
    315,164,339,175,339,175,365,189,396,205,396,205,431,221,457,235,491,248,491,248,522,264,553,279,580,296,580,296,612,315,634,328,657,344,657,344,679,357,701,37
    
    1,719,384,719,384,736,397,756,408,756,408,773,416,787,425,799,433,811,438,811,438,820,444,827,447,827,447,833,451,838,452,842,454,842,454,845,454,848,455,849,4
    
    55,850,456,850,456,851,456,851,456,851,456,852,456,852,456,852,456,852,456,852,456,852,456,852,456,852,456,852,456,852,456,852,456,852,456,852,456,852,456,852,
    
    456,852,456,852,456,852,456,852,456,852,456,852,456,852,456,852,456,852,456,852,456,852,456,852,456,852,456,444,913,111,444);
    var index = 0;
    var trNum = 0;
    function svetLayer(id)
    	{
    		this.name = dom?document.getElementById(id):ie?document.all[id]:ns?document.layers[id]:null;
    		if (this.name !== null)
    			{
    				this.css    = (dom||ie)?this.name.style:this.name;
    				this.x      = dom?this.css.pixelLeft:ie?parseInt(this.css.left):this.css.left;
    				this.y      = dom?this.css.pixelTop:ie?parseInt(this.css.top):this.css.top;
    				this.moveTo = moveTo;
    				return this;
    			}
    		else alert('Your layer does not exist');
    	}
    
    function moveTo(x,y)
    	{
    		if(dom||ie)
    			{
    				this.x=x;
    				this.y=y;
    				this.css.left=x;
    				this.css.top=y;
    			}
    		else this.css.moveTo(x,y);
    	}
    function timeline()
    	{
    		if(trNum < (path.length-1))
    			{
    				dhtml.moveTo(path[trNum],path[trNum+1])
    				trNum += 2;
    				setTimeout('timeline()',10);
    			}
    		else trNum=0; 
    	}
    window.onload=timeline;
    </script>
    
    
    
    <input type="button" onclick="ChangeStyle()" value="A+" />
    <input type="button" onclick="javascript:body.style.fontSize='0.65em'" value="A-" />
    <input type="button" onclick="javascript:body.style.fontSize='1em'" value="A" /><p/>
    </body>
    </html>

  6. #6
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    What are you doing with:
    Code:
    document.write(' <html><head>
    document.write('<script type=text/javascript>
    Also - is there a reason your closing and opening your script tags so much?
    Please post a link to the page on your site that contains the problematic script so we can check it out.
    Jeremy | jfein.net

  7. #7
    Join Date
    Sep 2010
    Location
    Hi Stalker.
    Posts
    148
    Thanks
    16
    Thanked 3 Times in 3 Posts

    Default

    I'm opening and closing them so much because I read that would be better. I'm not sure. Link:
    http://kapleenmusic.webfreehosting.net/cl0n3d

  8. #8
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Well - look at your page. Lots of code on it thats not being rendered... Shouldnt you fix it up?

    Edit:
    I've done some searching, and it appears that you can't save a file with javascript on a mac. I didnt test any of the things that I found on a windows computer, but if you have a windows you can check something out like: http://4umi.com/web/javascript/filewrite.php or http://www.galasoft.ch/myjavascript/...rer/index.html.
    But is it really necessary?
    Last edited by Nile; 11-03-2010 at 12:50 AM.
    Jeremy | jfein.net

  9. #9
    Join Date
    Sep 2010
    Location
    Hi Stalker.
    Posts
    148
    Thanks
    16
    Thanked 3 Times in 3 Posts

    Default

    Could someone point out on how to fix this code? This could be very important for a surprise later on.

Bookmarks

Posting Permissions

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