question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

encode date/view in URL fragment, so back button works

See original GitHub issue

Originally reported on Google Code with ID 388

I have a working example of supporting the back button fully by updating 
the hash tag of window.location (window.location.hash). I'm using a couple 
of things to make this possible:

- fullcalendar viewDisplay callback
- jQuery hashChange event plugin (see 1)
- Datejs (see 2)
- and some javascript to pull it all together and use hash tags like #week-
10-2010, #day-71-2010, or #month-3-2010

I'll document this on my blog but I suspect I am doing some things 
inefficiently (if I was more familiar with the fullcalendar source, I could 
probably get rid of Datejs) and it seems like something that people would 
commonly need.

I'll update this once I get my blog post in but feedback on whether it is 
desired or not would be great...

(1) http://benalman.com/code/projects/jquery-hashchange/docs/files/jquery-
ba-hashchange-js.html

(2) http://www.datejs.com/

Reported by cymenvig on 2010-03-11 18:16:37

Imported with 18 stars.

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:13 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
jamienkcommented, Oct 25, 2017

Just to be completely explicit, this works:

$(document).ready(function() {

    var today = new Date();
    var tmpYear = today.getFullYear();
    var tmpMonth = today.getMonth();
    var tmpDay = today.getDate();
    var tmpView = 'month';
    var vars = window.location.hash.split("&");
    for (var i = 0; i < vars.length; i++) 
    {
      if (vars[i].match("^#year")) tmpYear = vars[i].substring(6);
      if (vars[i].match("^month")) tmpMonth = vars[i].substring(6) - 1;
      if (vars[i].match("^day")) tmpDay = vars[i].substring(4);
      if (vars[i].match("^view")) tmpView = vars[i].substring(5);
    }


    // initialize the calendar...
    $('#calendar').fullCalendar({
    	events: 'index.php?j=y',
    	year: tmpYear,
		  month: tmpMonth,
		  day: tmpDay,
		  defaultView: tmpView,
		  viewRender: function (view) {
                var moment = $('#calendar').fullCalendar('getDate');
                if (moment) {
                    window.location.hash = 'year=' + moment.format('YYYY') + '&month=' + ( moment.format('M')
                        ) + '&day=' + moment.format('DD') + '&view=' + view.name;
                }
            }
    
        // put your options and callbacks here
    });
    
    var date = new Date(tmpYear, tmpMonth, tmpDay, 0, 0, 0);
    var dmom = $('#calendar').fullCalendar('getDate');
    if (dmom)
    {
    	if (date.getFullYear() != dmom.format('YYYY') || date.getMonth() != dmom.format('M') || date.getDate() != dmom.format('DD'))
      $('#calendar').fullCalendar('gotoDate', date);	
    }
    
    var view = $('#calendar').fullCalendar('getView');
    if (view.name != tmpView)
      $('#calendar').fullCalendar('changeView', tmpView);

});
0reactions
romblincommented, Nov 23, 2018

It’s been for a long time. Is anybody working on the issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Detecting Back Button/Hash Change in URL - Stack Overflow
It loads all the pages using AJAX - I have it set up to allow bookmarking by detecting the hash in the URL....
Read more >
Dao De Web (or: The Painful History of the URL) | Smellegant Code
The URL tells the application which room to display, and so the user can: Press the Back button to go back to the...
Read more >
JavaScript Event Calendar - FullCalendar
Provide default innerContent in eventContent so it can be wrapped. 26. List view, custom columns ... encode date/view in URL fragment, so back...
Read more >
URI fragment - Wikipedia
The fragment identifier introduced by a hash mark # is the optional last part of a URL for a document. It is typically...
Read more >
HTML Standard
If the element is being added by script, then so long as the event handlers are ... For example, the following markup fragment...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found