HTML5 pushState for back button and bookmarking support

2,089 views
Skip to first unread message

AJ Mercer

unread,
Aug 31, 2011, 7:30:22 AM8/31/11
to ang...@googlegroups.com
are there plans to implement window.history.pushState and  window.onpopstate
to replace the #! method?

I have just watch
by Michael Mahemoff and he recommends this way of doing it


I guess you would need to keep #! for browsers that do not have full HTML5 support.

--

AJ Mercer
<webonix:net strength="Industrial" /> | <webonix:org community="Open" />
http://twitter.com/webonix

Di Peng

unread,
Aug 31, 2011, 8:35:07 AM8/31/11
to ang...@googlegroups.com
Yes! I believe the new location service have that
Di

--
You received this message because you are subscribed to the Google Groups "angular" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.

Igor Minar

unread,
Aug 31, 2011, 11:00:02 AM8/31/11
to ang...@googlegroups.com
Yes. The new location service that I target to land in the master branch this week will use the html5 history apis when available.

/i

AJ Mercer

unread,
Sep 3, 2011, 1:05:43 AM9/3/11
to ang...@googlegroups.com
is it a part of the 0.10 release?

is this it??

Igor Minar

unread,
Sep 3, 2011, 1:40:44 AM9/3/11
to ang...@googlegroups.com
no the new location will be part of 0.10.1, we are still ironing out some issues.

/i

AJ Mercer

unread,
Sep 3, 2011, 1:53:46 AM9/3/11
to ang...@googlegroups.com
ok - thanks for the update.

Vojta Jina

unread,
Sep 5, 2011, 4:06:08 PM9/5/11
to ang...@googlegroups.com
Yep, with new $location you can configure it to use either hashbang (old) mode or html5 mode. When using html5 mode, $location will use nice urls in modern browsers with html5 support and fall back to using old hashbang urls when not supported...
As Igor said, it's already implemented, should be in next release...
V.

AJ Mercer

unread,
Sep 23, 2011, 12:00:42 AM9/23/11
to ang...@googlegroups.com
is there a sample/example app I can take a look at to see this in action?


--
You received this message because you are subscribed to the Google Groups "angular" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/2HtEKLE4_qwJ.

To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.

Igor Minar

unread,
Sep 23, 2011, 10:04:02 AM9/23/11
to ang...@googlegroups.com

We are converting docs.angularjs.org to the html5 mode. It's done and needs to be merged to master.  Check out the pending pull request in the meantime.

/i

On Sep 23, 2011 6:00 AM, "AJ Mercer" <ajme...@gmail.com> wrote:
> is there a sample/example app I can take a look at to see this in action?
>
>
> On 6 September 2011 04:06, Vojta Jina <vojta...@gmail.com> wrote:
>
>> Yep, with new $location you can configure it to use either hashbang (old)
>> mode or html5 mode. When using html5 mode, $location will use nice urls in
>> modern browsers with html5 support and fall back to using old hashbang urls
>> when not supported...
>> As Igor said, it's already implemented, should be in next release...
>> V.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "angular" group.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msg/angular/-/2HtEKLE4_qwJ.
>>
>> To post to this group, send email to ang...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> angular+u...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/angular?hl=en.
>>
>
>
>
> --
>
> *AJ Mercer*
> <webonix:net strength="Industrial" /> <http://webonix.net> | <webonix:org
> community="Open" /> <http://webonix.org>
> http://twitter.com/webonix
> Railo Community Manager <http://www.getrailo.org/index.cfm/community/team/>
>
> --
> You received this message because you are subscribed to the Google Groups "AngularJS" group.

Boris Gurvich

unread,
Sep 23, 2011, 11:49:24 AM9/23/11
to ang...@googlegroups.com
Hi Voita,

Does html5 mode support onbeforeunload ?

Thanks,
Boris.

On Mon, 05 Sep 2011 13:06:08 -0700, Vojta Jina <vojta...@gmail.com>
wrote:

Igor Minar

unread,
Sep 23, 2011, 12:24:49 PM9/23/11
to ang...@googlegroups.com

Can you be more specific?

/i

> --
> You received this message because you are subscribed to the Google Groups "AngularJS" group.

Boris Gurvich

unread,
Sep 23, 2011, 12:31:25 PM9/23/11
to ang...@googlegroups.com
Igor,

Regular HTML has javascript onbeforeunload, which will confirm with user
on page change.

Example: a user has made changes to form data and tries to navigate away
without saving, the script will confirm whether the user wants to save the
data before reloading or loading another page.

It was not possible to implement something like this in user space with
old $route/$location, so I'm wondering if HTML5 history API supports
onbeforeunload equivalent natively, or maybe it was accounted for in the
new AngularJS implementation?

Thank you,
Boris.

On Fri, 23 Sep 2011 09:24:49 -0700, Igor Minar <igor....@gmail.com>
wrote:

> Can you be more specific?
>
> /i
> On Sep 23, 2011 5:49 PM, "Boris Gurvich" <uni...@gmail.com> wrote:
>> Hi Voita,
>>
>> Does html5 mode support onbeforeunload ?
>>
>> Thanks,
>> Boris.
>>
>> On Mon, 05 Sep 2011 13:06:08 -0700, Vojta Jina <vojta...@gmail.com>
>> wrote:
>>

<snip>

Igor Minar

unread,
Sep 26, 2011, 10:36:36 PM9/26/11
to ang...@googlegroups.com
Angular is mostly just "regular javascript". So why can't you just register a listener for the onbeforeunload event on the window or $window object?

If you are looking for some kind of tighter integration, could you propose what it should look like? What is it that you are trying to achieve and can't with things as they are today?

/i


For more options, visit this group at
http://groups.google.com/group/angular?hl=en.


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+unsubscribe@googlegroups.com.

Boris Gurvich

unread,
Sep 26, 2011, 11:36:00 PM9/26/11
to ang...@googlegroups.com
Igor,

window.onbeforeunload takes care of page reload, window/tab close, and
change of URL.

It doesn't trigger on hash change, and $route.onChange() is too late to
catch user confirm action, because all logic of hash change has been done
already.

We had a conversation about it previously in this thread:
http://groups.google.com/group/angular/browse_thread/thread/f64e5a14fa33dd1a/57e2670aede35eef

Yesterday I've just opted not to use <a href="..."> at all or changing
$location hash directly, and implemented goTo(url) service method that
takes care of this, so this RFE is not a priority at all. This workaround
doesn't handle direct change of hash in address bar, but I can live with
it.

Thanks,
Boris.

<snip>


>>
<snip>
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups
>> "AngularJS" group.
>> To post to this group, send email to ang...@googlegroups.com.

>> To unsubscribe from this group, send email to angular+unsubscribe@**
>> googlegroups.com <angular%2Bunsu...@googlegroups.com>.
>> For more options, visit this group at http://groups.google.com/**
>> group/angular?hl=en <http://groups.google.com/group/angular?hl=en>.
>>
>>
>


Igor Minar

unread,
Sep 27, 2011, 8:49:01 AM9/27/11
to ang...@googlegroups.com
On Tue, Sep 27, 2011 at 5:36 AM, Boris Gurvich <uni...@gmail.com> wrote:
Igor,

window.onbeforeunload takes care of page reload, window/tab close, and change of URL.

It doesn't trigger on hash change, and $route.onChange() is too late to catch user confirm action, because all logic of hash change has been done already.

in 0.10.x we have "$beforeRouteChange" event that is fired before the route is changed, are you also looking for real "window.onbeforeunload" event in addition to this event?

/i
 

For more options, visit this group at http://groups.google.com/**
group/angular?hl=en <http://groups.google.com/group/angular?hl=en>.


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.


Boris Gurvich

unread,
Sep 27, 2011, 2:41:46 PM9/27/11
to ang...@googlegroups.com
On Tue, 27 Sep 2011 05:49:01 -0700, Igor Minar <ig...@angularjs.org> wrote:

> On Tue, Sep 27, 2011 at 5:36 AM, Boris Gurvich <uni...@gmail.com> wrote:
>
>> Igor,
>>
>> window.onbeforeunload takes care of page reload, window/tab close, and
>> change of URL.
>>
>> It doesn't trigger on hash change, and $route.onChange() is too late to
>> catch user confirm action, because all logic of hash change has been
>> done
>> already.
>>
>
> in 0.10.x we have "$beforeRouteChange" event that is fired before the
> route
> is changed,

Thanks. Right now I'm still on 0.9.16, the code doesn't work even on
0.9.19, and I'm just waiting for 1.0 to upgrade API integration.
The app is huge, so I have to minimize exposure to moving API target.

> are you also looking for real "window.onbeforeunload" event in
> addition to this event?

Yes, I've implemented handling both browser navigator and angular hash nav
events. If it is of an interest to anyone, I can isolate the
implementation and share.

Igor Minar

unread,
Sep 27, 2011, 3:12:21 PM9/27/11
to ang...@googlegroups.com
On Tue, Sep 27, 2011 at 8:41 PM, Boris Gurvich <uni...@gmail.com> wrote:
On Tue, 27 Sep 2011 05:49:01 -0700, Igor Minar <ig...@angularjs.org> wrote:

On Tue, Sep 27, 2011 at 5:36 AM, Boris Gurvich <uni...@gmail.com> wrote:

Igor,

window.onbeforeunload takes care of page reload, window/tab close, and
change of URL.

It doesn't trigger on hash change, and $route.onChange() is too late to
catch user confirm action, because all logic of hash change has been done
already.


in 0.10.x we have "$beforeRouteChange" event that is fired before the route
is changed,

Thanks. Right now I'm still on 0.9.16, the code doesn't work even on 0.9.19, and I'm just waiting for 1.0 to upgrade API integration.
The app is huge, so I have to minimize exposure to moving API target.

Have you written the tests yet? That would make upgrades much easier. I think that our apps are the same size or bigger and only tests allow us to confidently upgrade.
 


are you also looking for real "window.onbeforeunload" event in
addition to this event?

Yes, I've implemented handling both browser navigator and angular hash nav events. If it is of an interest to anyone, I can isolate the implementation and share.

sure, or just a list of requirements would be sufficient.

/i 

Boris Gurvich

unread,
Sep 27, 2011, 4:27:49 PM9/27/11
to ang...@googlegroups.com

I didn't find any doc on it, does $beforeRouteChange allow canceling the
route change?
If yes, i think that's flexible enough for any purpose.

Vojta Jina

unread,
Oct 2, 2011, 12:49:26 PM10/2/11
to ang...@googlegroups.com
There isn't direct api for cancelling navigation, so you have to do it on your own.
Search the archive, I'm pretty sure I've already discussed this.

$beforeRouteChange and $afterRouteChange events should help you with it...

V.
Reply all
Reply to author
Forward
0 new messages