Setting A Bookmark

15 views
Skip to first unread message

Bill Morrison

unread,
Sep 13, 2011, 12:16:11 PM9/13/11
to Google Web Toolkit
This is a simple question, but one I can't seem to find the answer to
(all searches return how-to's on implementing History)

I'm looking for the code needed to have my GWT application set a
bookmark in the users browser.

Thanks in advance!


Bill

Jens

unread,
Sep 13, 2011, 12:37:42 PM9/13/11
to google-we...@googlegroups.com
You should let the user decide to bookmark a page or not.

In general you have to use GWT's JSNI feature and wrap some native JavaScript to add a bookmark. As far as I know, Chrome and Opera do not support adding bookmarks via JavaScript.

-- J.

Bill Morrison

unread,
Sep 13, 2011, 12:40:14 PM9/13/11
to Google Web Toolkit
This is in response to the user pressing a 'Bookmark' button on the
page of course.

I'll dig into the Javascript side, thanks for the hint. If anyone has
any JSNI that shows this I'd love to not reinvent the wheel!

Eric Metcalf

unread,
Sep 13, 2011, 1:03:33 PM9/13/11
to Google Web Toolkit
Check out this documentation on history.
http://code.google.com/webtoolkit/articles/mvp-architecture.html#history

You want to set the 'state' of you application with your URL. You
append to the URL some data such as page to display and state of the
page and then call a method that will read the URL and display the
correct page with the correct state. In this way you can copy and
paste the URL into a different browser and it will show the current
page and state (bookmarked). Also make the method choose a default
page if no URL info has been appended.

http://myapp.com
AppController called
AppController checks the URL has no appended so appends "#home"
AppContoller calls fireCurrentHistoryState
fireCurrentHistoryState sees #home so displays home page
user clicks on setup link (use Hyperlink with "setup" as target
history token)
fireCurrentHistoryState sees #home so displays setup page

If someone bookmarks the setup page the AppController will call
fireCurrentHistoryState on load and display the setup page.
Reply all
Reply to author
Forward
0 new messages