Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #11 (permalink)  
Old August 29th, 2003, 03:16 PM
Authorized User
 
Join Date: Aug 2003
Location: San Jose, N/A, Costa Rica.
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

How would you change the following code, so that if the page is only 1 KB long (ie, not found) then retry to load it? :

By the way, the delays I put there are for that reason, that is, to give the server time to respond to the request, that code can be simply omited.
------------------

<html>
<body>

<h1>LRTP - Automatic ticket preprocessing program </h1>
<h2>By: Roberto Sala Hidalgo</h2>

<h3>This program will automatically open a range of tickets (by id) and save them locally for indexing purposes</h3>



<script type="text/javascript">

    function SaveToDisk(sUrl, sPath)
    {
        var x = new ActiveXObject("Msxml2.XMLHTTP.3.0");
        x.open("GET", sUrl, false);
        x.send();
        if (x.status == 200)
        {
          var fso = new ActiveXObject("Scripting.FileSystemObject");
          var fileDest = fso.CreateTextFile(sPath, true, true);
          if (fileDest)
          {
             fileDest.Write(x.responseText);
             fileDest.close();
          }
          else
          {
             alert("unable to create file " + sPath);
          }
        }
        else
        {
          alert("HTTP error status " + x.status + " from " + sUrl);
        }

    }


for (i = 4000; i <= 4020; i++)
{
  document.write("Accesing ticket ID = " + i + " ")
  document.write('http://lookup.pg.com/lookup/scview.jsp?id=' + i);

  //popup('http://lookup.pg.com/lookup/scview.jsp?id=' + i);
  for (delay = 1; delay <= 900000; delay++)
  { } // delay

//window.open('http://lookup.pg.com/lookup/scview.jsp?id=' + i);
  SaveToDisk ('http://lookup.pg.com/lookup/scview.jsp?id=' + i, 'c:\\temp\\' + i + '.htm');

  for (delay = 1; delay <= 1200000; delay++)
  { } // delay

  document.write("<br>")
}
</script>


</body>
</html>


-----------------
Thanks,
Roberto

Reply With Quote
  #12 (permalink)  
Old September 2nd, 2003, 10:19 AM
Authorized User
 
Join Date: Aug 2003
Location: San Jose, N/A, Costa Rica.
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Another way to ask this is this: is it possible to check on that file's size so that if its below 1 KB (which means it was loaded ok, but "not found") it may retry again?

Reply With Quote
  #13 (permalink)  
Old September 3rd, 2003, 08:54 PM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to stalker Send a message via MSN to stalker
Default

if you want to know if the page was not found, forbidden, etc you must check it's status

x.status == 200

in this expression you check if the status is 200 means that the page was loaded sucessfully.. if it is 404 instead of 200 means it was not found, if it was 403 means it was forbidden bla bla bla.. to know all the http status codes search for this string "http status codes" in any search engine :)

good luck :)

Reply With Quote
  #14 (permalink)  
Old September 4th, 2003, 08:19 AM
Authorized User
 
Join Date: Aug 2003
Location: San Jose, N/A, Costa Rica.
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, I know about the HTTP error codes, but this is just not the issue: actually, they load just fine, but, the page that loads (with no errors) from the server is a javascript page titled "Not found", it is not a 404 HTML error, its a server-generated page.

Any page that was succesfully generated from the server would be at lease 8KB. Any page that was unsuccesfully (i.e., "Not found") generated from the server would be less than 1KB in size.

So the idea is to ask if the size is less than 1KB then attempt to reload it about, say 5 times. I will search for the function that asks for HTML page size in KB, but I'd be fantastic if someone can tell me that.

Thanks,
Roberto



Reply With Quote
  #15 (permalink)  
Old September 4th, 2003, 09:12 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Roberto,

as you know from the code I gave you before, x.responseText gives you the file contents, so x.responseText.length should give you its size. I guess you could do something like this:
Code:
var x = new ActiveXObject("Msxml2.XMLHTTP.3.0");
x.open("GET", sUrl, false);
x.send();
var retryCount = 0;
while (x.status==200 && x.responseText.length<1024 && retryCount<5)
{
  x.send();
  retryCount++;
}
you get the idea...

rgds
Phil
Reply With Quote
  #16 (permalink)  
Old September 5th, 2003, 02:30 PM
Authorized User
 
Join Date: Aug 2003
Location: San Jose, N/A, Costa Rica.
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I integrated that code to my page, but I get an error message saying "Unspecified error Code 0", any idea about what that error might be? I get it on a file that does not exist... I'm still making tests, but I don't know what that error refers to specifically? Comments?...

Thanks for all the help!
Roberto


Reply With Quote
  #17 (permalink)  
Old January 27th, 2005, 01:48 AM
Registered User
 
Join Date: Jan 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by rsalah
 Hi, I was wondering if anyone here knows this:
You open an html page opened by javascript, and you want to save it to your local hard drive, but not with the menu File->Save as, but rather, automatically, that is, page opened, page saved on C:

Can anyone please help? It's very important.

If you can include a piece of source code for this, it would really be helpful. Thanks!


Hola !!! Necesito comunicarme contigo porque tengo el mismo problema, efrainrv@hotmail.com
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
html form - save help bunnyhead HTML Code Clinic 2 January 24th, 2005 05:55 AM
can't save html /css website !! ca123 CSS Cascading Style Sheets 2 November 15th, 2004 07:29 PM
How to save string value as html file? android66 Javascript 0 September 3rd, 2004 12:00 AM
html page save to excel format mateenmohd Javascript 2 January 17th, 2004 05:48 AM
how to save html output of xslt to file wtalbin XSLT 2 August 15th, 2003 09:14 PM



All times are GMT -4. The time now is 07:52 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.