Results 1 to 7 of 7

Thread: Javascript - wait until page is loaded to proceed to next action

  1. #1
    Senior Member
    Join Date
    Sep 2006
    Location
    UK
    Posts
    1,011
    Thanks
    17
    Thanked
    14 times in 13 posts
    • Craig321's system
      • Motherboard:
      • Asus P8P67 Pro
      • CPU:
      • i7 2600k
      • Memory:
      • 4x 4GB Corsair XMS3 1600MHz
      • Storage:
      • 120GB OCZ Vertex 3
      • Graphics card(s):
      • Asus GTX480 1536MB
      • PSU:
      • 650W Corsair HX
      • Case:
      • Fractal Design Define R3
      • Operating System:
      • Windows 7 Professional 64-bit
      • Monitor(s):
      • Dell U2410

    Javascript - wait until page is loaded to proceed to next action

    Hi,

    I've been using the FormSaver plug-in recently for Mozilla.

    Basically, when you're on the page you click bookmark form, then when you go back to that page you click the bookmark you run that bookmark and it fills out the form using some JavaScript, pretty simple.

    At the beginning of the bookmark I have added window.location = "http://www.website.com/form/"; so the bookmark takes me to the website as well as fills it out.

    The problem with that is the rest of the JavaScript (to fill the form) gets run before the page has a chance to load.

    So, is there any way I can make the JavaScript stop until the page is loaded?

    Thanks,
    Craig.

  2. #2
    Flower Child stytagm's Avatar
    Join Date
    Aug 2004
    Location
    London
    Posts
    754
    Thanks
    47
    Thanked
    23 times in 18 posts
    They told me I was gullible ... and I believed them.

  3. #3
    Senior Member
    Join Date
    Sep 2006
    Location
    UK
    Posts
    1,011
    Thanks
    17
    Thanked
    14 times in 13 posts
    • Craig321's system
      • Motherboard:
      • Asus P8P67 Pro
      • CPU:
      • i7 2600k
      • Memory:
      • 4x 4GB Corsair XMS3 1600MHz
      • Storage:
      • 120GB OCZ Vertex 3
      • Graphics card(s):
      • Asus GTX480 1536MB
      • PSU:
      • 650W Corsair HX
      • Case:
      • Fractal Design Define R3
      • Operating System:
      • Windows 7 Professional 64-bit
      • Monitor(s):
      • Dell U2410
    Basically this FormSaver saves a bookmark, in the bookmarks URL is some JavaScript. Then when you want to auto fill that page again you go back to it and click the bookmark. So if I was to go to that web page and paste the code the add-on had generated into the address bar then it would fill out the form, it works like JavaScript injection.

    So I need some code in that JavaScript that will take me to the webpage before running the form-filling code.

    I think onLoad="" needs to be used within HTML?

    Thanks,
    Craig.

  4. #4
    HEXUS.net Webmaster
    Join Date
    Jul 2003
    Location
    UK
    Posts
    3,108
    Thanks
    1
    Thanked
    0 times in 0 posts
    pretty sure you can have window.onLoad e.g.

    Code:
    window.location = "http://www.website.com/form/";
    checkLoad();
    
    function checkLoad()
    {
         if (window.onLoad)
         {
              // call form population script
         } else {
              setTimeout('checkLoad();', 1000)
         }
    }
    Last edited by Iain; 21-11-2006 at 06:57 PM.

  5. #5
    Senior Member
    Join Date
    Sep 2006
    Location
    UK
    Posts
    1,011
    Thanks
    17
    Thanked
    14 times in 13 posts
    • Craig321's system
      • Motherboard:
      • Asus P8P67 Pro
      • CPU:
      • i7 2600k
      • Memory:
      • 4x 4GB Corsair XMS3 1600MHz
      • Storage:
      • 120GB OCZ Vertex 3
      • Graphics card(s):
      • Asus GTX480 1536MB
      • PSU:
      • 650W Corsair HX
      • Case:
      • Fractal Design Define R3
      • Operating System:
      • Windows 7 Professional 64-bit
      • Monitor(s):
      • Dell U2410
    Hello,

    I attempted to integrate that into the JavaScript form filling code, it loaded the form web page but didn't auto-fill

    Here's some example code:

    Code:
    javascript:(function(){ var error = 0; var keepError = 'I tried my best, but I was unable to fill in your form perfectly.<br><br>'; var formsArray = content.document.getElementsByTagName('form');try{ formsArray[0]['q'].value='MYSEARCH'; } catch(e){ error = 1; keepError = keepError + '- Form field q could not be found.<br>'; } try { formsArray[0].elements[4].checked=true; } catch(e){ error = 1; keepError = keepError + '- Form radio meta could not be found.<br>'; }  if(error == 1){ var newwin = window.open('', 'formsaver', 'HEIGHT=250,WIDTH=600,resizable=1,scrollbars=1'); newwin.document.writeln(keepError); newwin.document.close(); newwin.focus(); } })()
    That's a sample of MYSEARCH being autofilled on the Google homepage.

    So, integrating it with the script above should go something like this?:

    Code:
    window.location = "http://www.website.com/form/";
    checkLoad();
    
    function checkLoad()
    {
         if (window.onLoad)
         {
              (function(){ var error = 0; var keepError = 'I tried my best, but I was        unable to fill in your form perfectly.<br><br>'; var formsArray = content.document.getElementsByTagName('form');try{ formsArray[0]['q'].value='MYSEARCH'; } catch(e){ error = 1; keepError = keepError + '- Form field q could not be found.<br>'; } try { formsArray[0].elements[4].checked=true; } catch(e){ error = 1; keepError = keepError + '- Form radio meta could not be found.<br>'; }  if(error == 1){ var newwin = window.open('', 'formsaver', 'HEIGHT=250,WIDTH=600,resizable=1,scrollbars=1'); newwin.document.writeln(keepError); newwin.document.close(); newwin.focus(); } })()
         } else {
              setTimeout('checkLoad();', 1000)
         }
    }
    Last edited by Craig321; 22-11-2006 at 05:06 AM.

  6. #6
    HEXUS.net Webmaster
    Join Date
    Jul 2003
    Location
    UK
    Posts
    3,108
    Thanks
    1
    Thanked
    0 times in 0 posts
    too many brackets in your code, try this

    Code:
    window.location = "http://www.website.com/form/";
    checkLoad();
    
    function checkLoad()
    {
    	if (window.onLoad)
    	{
    		completeForm();
    	} else {
    		setTimeout('checkLoad()', 1000);
    	}
    }
    
    function completeForm()
    {
    	var error = 0;
    	var keepError = 'I tried my best, but I was unable to fill in your form perfectly.<br><br>';
    	var formsArray = content.document.getElementsByTagName('form');
    	try
    	{
    		formsArray[0]['q'].value='MYSEARCH';
    	}
    	catch(e)
    	{
    		error = 1; 
    		keepError = keepError + '- Form field q could not be found.<br>';
    	} 
    	try
    	{
    		formsArray[0].elements[4].checked=true;
    	} 
    	catch(e)
    	{
    		error = 1; 
    		keepError = keepError + '- Form radio meta could not be found.<br>';
    	} 
    	if(error == 1)
    	{
    		var newwin = window.open('', 'formsaver', 'HEIGHT=250,WIDTH=600,resizable=1,scrollbars=1');
    		newwin.document.writeln(keepError);
    		newwin.document.close();
    		newwin.focus();
    	} 
    }

  7. #7
    Senior Member
    Join Date
    Sep 2006
    Location
    UK
    Posts
    1,011
    Thanks
    17
    Thanked
    14 times in 13 posts
    • Craig321's system
      • Motherboard:
      • Asus P8P67 Pro
      • CPU:
      • i7 2600k
      • Memory:
      • 4x 4GB Corsair XMS3 1600MHz
      • Storage:
      • 120GB OCZ Vertex 3
      • Graphics card(s):
      • Asus GTX480 1536MB
      • PSU:
      • 650W Corsair HX
      • Case:
      • Fractal Design Define R3
      • Operating System:
      • Windows 7 Professional 64-bit
      • Monitor(s):
      • Dell U2410
    Hello,

    I just made that all into one line (need to for the bookmark) and it takes me to the website but still doesn't fill the form

    Any ideas please?

    Thanks,
    Craig.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Slow boot up?
    By streetster in forum Software
    Replies: 14
    Last Post: 06-12-2010, 06:57 AM
  2. Replies: 3
    Last Post: 24-02-2006, 05:28 PM
  3. 8pm tonight... AUT2004 - Action UT
    By scottyman in forum Gaming
    Replies: 14
    Last Post: 11-09-2004, 02:42 PM
  4. The Action Movie
    By Private_mojo in forum Consumer Electronics
    Replies: 7
    Last Post: 14-07-2004, 04:53 PM

Posting Permissions

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