views:

17

answers:

1

We have a Silverlight Prism project with complex state information stored in the browser bookmark. This allows us to share bookmarks/links which will restore the application to the exact same visual state.

We do not however want trivial bookmark changes (i.e. non-navigation changes) to result in a browser history entry. Otherwise the browser back/forward buttons would also make simple changes (things like simple list selections, tab selections etc).

Q: Is there a way to still change the browser bookmark URL, but exclude it from the browser history, or (failing that) is it possible to remove entries from the browser history?

Our visual states are prioritised, so we know which ones actually should affect navigation and which are just for decoration. This can be determined either before the URL is changed or after, so your answer can use either situation. We can add a specific marker to the bookmark, indicating it should not be archived, if that would also help your solution.

Thanks

A: 

I created one answer myself, but would prefer not to rely on JavaScript features. I also need to check that window.location.replace is supported by all browsers.

I now call this method with a flag, to say if I want the bookmarking ignored in the browser history:

public void NavigateToBookmark(string bookMarkUrl, bool replaceUrl)
{
    if (replaceUrl)
    {
        HtmlPage.Window.Invoke("NavReplace", bookMarkUrl);
    }
    else
    {
        HtmlPage.Window.NavigateToBookmark(bookMarkUrl);
    }
}

then add this JavaScript in the Silverlight hosting page:

 function NavReplace(url) {
            var newurl = parent.location.href;
            var index = newurl.indexOf("#");
            if (index > 0) {
                newurl = newurl.substr(0, newurl.indexOf("#"));
            }
            window.location.replace(newurl + "#" + url);
        }

Any takers for a better way to do this?

Enough already