Click to See Complete Forum and Search --> : Get Size In Bytes


deathswan
12-30-2003, 12:31 PM
Need some help with javascript to get the size in bytes of a url page.

fredmv
12-30-2003, 01:21 PM
Welcome to the forums.

This, by default will only work in IE (since it uses an ActiveX scripting object). However, you could get it working in Mozilla by using XMLHttpRequest instead as the constructor.<script type="text/javascript">
//<![CDATA[
function sendRequest(url)
{
var response = null;
var connection = new ActiveXObject("Microsoft.XMLHTTP");
try
{
connection.open("GET", url, false);
connection.send();
if(connection.readyState == 4) response = connection.responseText;
}
catch(e)
{
alert("ERROR: The remote host could not be found or the connection was refused.");
return false;
}
alert(response.length + ' bytes.');
return false;
}
//]]>
</script><form action="#" onsubmit="return sendRequest(elements[0].value);">
<div>
<input type="text" style="width: 250px;" value="http://www.google.com/" />
<input type="submit" value="Send GET Request" />
</div>
</form>

zachzach
12-30-2003, 01:24 PM
asp has the TextStream(badly named, it should be called the FileStream)/File System Object built in which will do that for u

deathswan
12-30-2003, 07:13 PM
fredmv, it doesnt work for me. mabye im not embedding it into the html properly. do certain parts have to go into the head, body, etc?

zachzach
01-02-2004, 12:49 PM
asp i know can do it, also, activeX controls(even emmbedded ones in vbscript/javascript/jscript) only work in IE.
ASP has extensive File things, so try posting something similar to this thread in the asp section
also i think php could do it, but you might wana ask PeoFeo or Pyro about that

Khalid Ali
01-02-2004, 01:14 PM
The best solution will be server side scripting..and if its server side then no question about php will be the best and most likely lost widely avaailable on commercial webhosting company's web servers.