Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

JS/DOM Question

  • 21-09-2005 04:35PM
    #1
    Registered Users, Registered Users 2 Posts: 55,740 ✭✭✭✭


    Hi all,

    I'm trying to adapt a function that calculates the size of images on a webpage. The function is as follows:
    function calculate()
    {
    	if (!document.fileSize)
    	{
    		alert('This script does not work in your browser.');
    		return;
    	}
    	var size = (document.fileSize)*1;
    	var y = document.images;
    	var imglength = 0;
    	for (i=0;i<y.length;i++)
    	{
    		imglength += (y[i].fileSize)*1;
    	}
    	var total = size + imglength;
    	var writestring = 'File size HTML: ' + size;
    	writestring += '\nFile size images: ' + imglength;
    	writestring += '\nTotal file size: ' + total;
    	if (total > 40000) writestring += "\nFile too large!";
    	alert(writestring);
    }
    
    What I'm trying to do is pass a URL as a parameter instead of just using the current page. I'm not a DOM expert, so I'm not sure if its possible using 'document.whatever'. Any suggestions? Intended usage would be:

    calculate('http://www.google.ie/index.html')

    Is it possible? Thanks in advance...


Comments

  • Registered Users, Registered Users 2 Posts: 55,740 ✭✭✭✭Mr E


    Actually in hindsight, I don't think it can be done like this. The page will still need to be physically loaded for this function to work. I'll figure out a different way of doing it. Cheers.....


  • Registered Users, Registered Users 2 Posts: 1,268 ✭✭✭hostyle


    Javascript use of the DOM as you have figured out is client side only :) Most server side languages are well able to do this sort of thing - PHP in particular is probably well suited for this exact thing.


Advertisement