GetScrollY for WebGadget

Share your advanced PureBasic knowledge/code with the community.
breeze4me
Enthusiast
Enthusiast
Posts: 633
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

GetScrollY for WebGadget

Post 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
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Post by Hroudtwolf »

Thanks for sharing.

Best regards

Wolf
User avatar
kenmo
Addict
Addict
Posts: 2047
Joined: Tue Dec 23, 2003 3:54 am

Re: GetScrollY for WebGadget

Post by kenmo »

A decade later, the three links are dead, but the code is exactly what I needed.

Thanks!
Post Reply