Search code examples
c#monowebkitanchorwebkit-sharp

webkit-sharp scroll to an HTML anchor tag


I have a webkit-sharp WebView which I am using to display HTMLvia the LoadString method.

The webview is placed in a ScrolledWindow the ScrolledWindow is placed in a Gtk Window.

I want to be able to tell the WebView to scroll to a specific part of the HTML. Normally one would do this using an anchor.

I have defined an anchor and some JavaScript to jump to that anchor, I call the JavaScript via the ExecuteScript method. This does nothing at all.

I have also tried adding a button to the HTML that calls the JavaScript. This also does nothing.

Is there something I can do to make this work, to make it so I can scroll to a known location in the page?

Update: I can make this work by saving the HTML to a file and then loading from there using a URL which tells it to scroll. However I would like to avoid doing that because of the performance hit of writing the page to disk before displaying it.


Solution

  • The JavaScript to jump to that anchor, doesn't work while the page is still loading, By waiting for the page load to finish (there is an event for it) then running the script I made it work.