Page 1 of 1

GetScrollY for WebGadget

Posted: Mon Dec 24, 2007 8:10 pm
by breeze4me
GetGadgetAttribute(gadget, #PB_Web_ScrollY) command does not return correct value at some web sites. (returned value is always 0)

It is because the declaration of DOCTYPE in that site prevents using document.body.scrollTop.
http://aranea.zuavra.net/index.php/5/
http://www.evolt.org/article/document_b ... index.html
http://www.quirksmode.org/js/doctypes.html

In that case, this function will be helpful.

Code: Select all

Procedure WebGadget_GetScrollY(WebGadNumber)
  Protected Browser.IWebBrowser2 = GetWindowLong_(GadgetID(WebGadNumber), #GWL_USERDATA)
  Protected res, scrollY = GetGadgetAttribute(WebGadNumber, #PB_Web_ScrollY)
  Protected DocumentDispatch.IDispatch, Document.IHTMLDocument3, Element.IHTMLElement2, DocElement.IHTMLElement
  If Browser
    If Browser\get_Document(@DocumentDispatch) = #S_OK And DocumentDispatch
      If DocumentDispatch\QueryInterface(?IID_IHTMLDocument3, @Document) = #S_OK And Document
        If Document\get_documentElement(@DocElement) = #S_OK And DocElement
          If docElement\QueryInterface(?IID_IHTMLElement2, @Element) = #S_OK And Element
            If Element\get_scrollTop(@res) <> #S_OK
              res = 0
            EndIf
            Element\Release()
          EndIf
          DocElement\Release()
        EndIf
        Document\Release()
      EndIf
      DocumentDispatch\Release()
    EndIf
  EndIf
;   If scrollY And res = 0 : res = scrollY : EndIf  
  If scrollY : res = scrollY : EndIf
  ProcedureReturn res
EndProcedure

DataSection
  IID_IHTMLDocument3:  ;{3050F485-98B5-11CF-BB82-00AA00BDCE0B}
    Data.l $3050F485
    Data.w $98B5,$11CF
    Data.b $BB,$82,$00,$AA,$00,$BD,$CE,$0B
  IID_IHTMLElement2:   ;3050f434-98b5-11cf-bb82-00aa00bdce0b
    Data.l $3050F434
    Data.w $98B5, $11CF
    Data.b $BB, $82, $00, $AA, $00, $BD, $CE, $0B
EndDataSection

Posted: Wed Jan 02, 2008 1:09 am
by Hroudtwolf
Thanks for sharing.

Best regards

Wolf

Re: GetScrollY for WebGadget

Posted: Mon Nov 05, 2018 4:13 pm
by kenmo
A decade later, the three links are dead, but the code is exactly what I needed.

Thanks!