views:

23

answers:

2

I want to persist the user's location in the document he or she is browsing, then bring them back to that spot when they return from tombstoning or between sessions.

My first approach was to wrap the browser component in a scrollviewer, but it turns out it handles its own scrolling and the scrollviewer never changes its verticaloffset.

My guess is that the browser component must have a scrollviewer or something like it embedded in it. I need to get the verticaloffset and scroll to an offset.

Any guesses how to get there?

My next approach would be a painful mish-mash of javascript and c# to figure out where they are...

+1  A: 

Because of the way the WebBrowser control is built you'll need to track scrolling in Javascript then pass the location to managed code to handle storage of that value.

On resuming you'll need to have the managed code pass the scroll position to a Javascript function to reset the scroll position.

That's the theory but I haven't looked at the funcitonality around javascript scrolling events in the WebBrowser yet. That's the only place I can see possible problems.
Would be good to hear how you get on.

Matt Lacey
That's exactly what I meant by a painful mish-mash... I'm not the king of javascript, but I think I have to ask elements their vertical offset and visibility. Plan B here is to give tags sequential IDs, then ask each if it is visible and how far from the top. <p id="1"> JQuery can make it easier, but still not as nice (or efficient) as asking a scrollviewer for offset. I don't think I can ask "What is visible on screen?" directly, but can ask each element "Are you on screen?"
jeffa00
A: 

I've accepted Matt's answer, but I want to put in some details here. I'm also going to blog about how I did it once I'm completely done.

Since the WebBrowser component is essentially a black-box, you don't have as much control as I would like. Having said that, it is possible to get and set the vertical offset.

Javascript lets you ask for the value, but different browsers use different variations on HOW to ask. For THIS case I only have one browser to worry about.

First I make a couple of simple javascript functions:

function getVerticalOffset() {
    return document.body.scrollTop;
}

function setVerticalOffset(offset) {
    document.body.scrollTop = offset;
}

Next I call into the WebBrowser using the InvokeScript method on the browser object.

I'll post an update here with a link to my blog when I get the full write-up done.

jeffa00
Definitely getting mixed results with the InvokeScript and ScriptNotify. Also with Browser control seemingly failing to load CSS sometimes. All files coming from isolated storage. Can't imagine why it fails to load only some of the time. Hmm.
jeffa00