AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Detect when a page is loaded (reliable, cross-browser)

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
keyboardfreak



Joined: 09 Oct 2004
Posts: 143
Location: Budapest, Hungary

PostPosted: Mon Aug 25, 2008 7:54 pm    Post subject: Detect when a page is loaded (reliable, cross-browser) Reply with quote

I needed this feature and I've seen there was no solution which worked reliably in Firefox and Opera (I don't use IE, I assume there is some COM solution for it).

It uses user Javascript to monitor when the page is loaded and modifies the page title if it's loaded, so one can query it with wingetttitle.

For Firefox GreaseMonkey needs to be installed for the script to work, Opera has the necessary functionality built-in.

It's not a pure AutoHotkey solution, but at least it works reliably.

Code:
// ==UserScript==
// @name           loaded
// @namespace      my
// @description    indicate if a page is loded
// @include        http://www.cnn.com
// ==/UserScript==


window.addEventListener(
  'load',
  function (e) {
    document.title += " [loaded]";
 }, false);



See also this topic for an other feature using the same technique.


Last edited by keyboardfreak on Fri Aug 29, 2008 4:06 pm; edited 1 time in total
Back to top
View user's profile Send private message
tank



Joined: 21 Dec 2007
Posts: 1033

PostPosted: Mon Aug 25, 2008 8:56 pm    Post subject: Re: Detect when a page is loaded (reliable, cross-browser) Reply with quote

keyboardfreak wrote:
I needed this feature and I've seen there was no solution which worked reliably in Firefox and Opera (I don't use IE, I assume there is some COM solution for it)

Unfortunately there is no COM interface to the afore mentioned browsers thus no AHK COM solution to be had
Thank you keyboardfreak this has been many times asked for and is the best idea I have seen but it as you mentioned isnt an ahk solution but a Grease Monkey/Javascript Solution. Albeit a pretty darn good one
I think once Firefox exposes its internal methods and properties to other languages other than mozilla plug in based then the move from IE to mozilla in the corp world can finally begin. But not untill then
another interesting solution I found is
http://www.autohotkey.com/forum/viewtopic.php?t=18567&highlight=statusbarwait+firefox
garry wrote:
this is for Mozilla Firefox:
Code:
;-- from AUTOWQ german forum
;-- http://de.autohotkey.com/forum/topic29.html
#Persistent
UR=http://www.screamer-radio.com/
SC=Screamer      ;title
IE=%A_programfiles%\Mozilla Firefox\firefox.exe
CL=ahk_class MozillaWindowClass

Run,%IE% %UR%,,max
WinWait,%SC%
IfWinNotActive,%SC%,,WinActivate,%SC%
WinWaitActive,%SC%
Sleep,300
SetTimer,FireFoxLoadDetect,500
Return

FireFoxLoadDetect:    ;check firefox rotary wheel
col32:=0xB2B2B2
col16:=0xB5B2B5
WinGetPos,,,WI,HI,A
;---Firefox 1.5 / 2.0 ------
Wi -= 16                            ; Position from wheel = Windowswidth -16
PixelGetColor, OutputVar, Wi, 41    ; 41 = Position from top

if outputvar in %col16%,%col32%
  {
  msgbox,%UR% is open
  ExitApp
  }
return


As far as COM IE and Gui Browsers go
http://www.autohotkey.com/forum/viewtopic.php?t=34972&highlight=
The above link is a complete COM IE Gui Browser tutorial
This is just an excerpt the first 2 snippets do not standalone but the 3rd one that I got from Sean does
tank wrote:
wait for it to finish loading
Code:
loop
      If (rdy:=COM_Invoke(pwb,"readyState") = 4)
         break
another way to check if a page has loaded using javascript via com
Code:
pwin:=COM_Invoke(doc:=COM_Invoke(pwb,"Document"),"parentWindow")   
   if pwin is integer
      loop
         If rdy:=COM_Invoke(pwin, "execScript","var rdy=document.readyState","rdy") = "complete" 
            break

of course always release objects not textyou wouldnt release rdy but you would release doc in the example above
a comletely independent way to check readystate requires tab if enabled to be the selected tab but doesnt require the window to be active
http://www.autohotkey.com/forum/viewtopic.php?t=19256&postdays=0&postorder=asc&start=0
Sean wrote:
It'll check whether a webpage is completely loaded or not in the active Internet Explorer.

NEED the latest COM Standard Library.

Code:
; Run, iexplore.exe http://www.google.com/
MsgBox, % IEReady()
Return

IEReady(hIESvr = 0)
{
   If Not   hIESvr
   {
      Loop,   50
      {
         ControlGet, hIESvr, hWnd, , Internet Explorer_Server1, A ; ahk_class IEFrame
         If   hIESvr
            Break
         Else   Sleep 100
      }
      If Not   hIESvr
         Return   """Internet Explorer_Server"" Not Found."
   }
   Else
   {
      WinGetClass, sClass, ahk_id %hIESvr%
      If Not   sClass == "Internet Explorer_Server"
         Return   "The specified control is not ""Internet Explorer_Server""."
   }

   COM_Init()
   If   DllCall("SendMessageTimeout", "Uint", hIESvr, "Uint", DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT"), "Uint", 0, "Uint", 0, "Uint", 2, "Uint", 1000, "UintP", lResult)
   &&   DllCall("oleacc\ObjectFromLresult", "Uint", lResult, "Uint", COM_GUID4String(IID_IHTMLDocument2,"{332C4425-26CB-11D0-B483-00C04FD90119}"), "int", 0, "UintP", pdoc)=0
   &&   pdoc && pweb:=COM_QueryService(pdoc,IID_IWebBrowserApp:="{0002DF05-0000-0000-C000-000000000046}")
      Loop
         If   COM_Invoke(pweb, "ReadyState") = 4
            Break
         Else   Sleep 500
   COM_Release(pdoc)
   COM_Release(pweb)
   COM_Term()
   Return   pweb ? "DONE!" : False
}

_________________
Read this
Com
Automate IE7 with Tabs
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5390
Location: /b/

PostPosted: Mon Aug 25, 2008 9:55 pm    Post subject: Reply with quote

Simple yet effective, another why didn't I think of that Razz If there are any GM clones for IE window.attachEvent('onload',function (){document.title+=' [loaded]';}); would be a valid hook.
_________________

Back to top
View user's profile Send private message Visit poster's website
Krogdor



Joined: 18 Apr 2008
Posts: 1145
Location: The Interwebs

PostPosted: Tue Aug 26, 2008 12:03 am    Post subject: Reply with quote

Oooh, I like it Very Happy

Thanks for posting this.
_________________
PlayAHK! Try it out Very Happy
Back to top
View user's profile Send private message AIM Address
tank



Joined: 21 Dec 2007
Posts: 1033

PostPosted: Tue Aug 26, 2008 12:57 am    Post subject: Reply with quote

i tried injecting this into IE and it failed to update the title ?? even tried updating title with
Code:
javascript:void(document.title="[loaded]")
nothing Crying or Very sad
_________________
Read this
Com
Automate IE7 with Tabs
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5390
Location: /b/

PostPosted: Tue Aug 26, 2008 8:30 am    Post subject: Reply with quote

tank wrote:
i tried injecting this into IE and it failed to update the title
Not sure why, perhaps it's an anti-XSS rule. Firefox doesn't have this problem. Here's an example of the embedded script, which works.
_________________

Back to top
View user's profile Send private message Visit poster's website
tank



Joined: 21 Dec 2007
Posts: 1033

PostPosted: Tue Aug 26, 2008 11:42 am    Post subject: Reply with quote

Titan wrote:
tank wrote:
i tried injecting this into IE and it failed to update the title
Not sure why, perhaps it's an anti-XSS rule. Firefox doesn't have this problem. Here's an example of the embedded script, which works.
oh i know thats why i think its odd
its valid javascript it should work
its very odd indeed
Im gonna do some research of my own see if i can root it out for sure
_________________
Read this
Com
Automate IE7 with Tabs
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group