I need to get an event for escape key from fullscreen in highcharts so that I can adjust the height of the container after escaping from fullscreen.
            Asked
            
        
        
            Active
            
        
            Viewed 1,350 times
        
    2 Answers
1
            
            
        Highcharts requests fullscreen from the browser.
You could listen for various fullscreenchange events, and do some action based on it:
if (document.addEventListener) {
  document.addEventListener('webkitfullscreenchange', exitHandler, false);
  document.addEventListener('mozfullscreenchange', exitHandler, false);
  document.addEventListener('fullscreenchange', exitHandler, false);
  document.addEventListener('MSFullscreenChange', exitHandler, false);
}
function exitHandler() {
  if (!document.webkitIsFullScreen && !document.mozFullScreen && !document.msFullscreenElement) {
    console.log('Exiting fullscreen. Doing chart stuff.');
    setContainerHeight(); // do your magic
  }
}
See this JSFiddle demonstration or see this discussion on the general case of detecting fullscreening.
        Halvor Holsten Strand
        
- 19,829
 - 17
 - 83
 - 99
 
1
            
            
        While the above works, I thought I'd throw out my solution as it wasn't ideal for my environment (multiple charts on the same page, as described here; partials linked to modules that have different needs).
I ended up using the Highcharts responsive callback option to execute code when a chart is exiting fullscreen mode.
    responsive: {
        rules: [{
            condition: {
                // A callback function to gain complete control on when the responsive rule applies. Return true if it applies
                callback: function () {
                    
                    if (this.chartHeight > (window.innerHeight / 2) || this.chartWidth > (window.innerWidth / 2)) {
                        console.log('responsive cb true:', this.renderTo.id);
                        _fsChartID = this.renderTo.id;
                        return true;
                    } else {
                        console.log('responsive cb false:', this.renderTo.id);
                        if (this.renderTo.id === _fsChartID) { // only hit when exiting fullscreen
                            _fsChartID = null; // reset _fsChartID to prevent infinite loop
                            this.redraw(); // call whatever function you need when exiting fullscreen
                        }
                        return false;
                    }                
                }
            }
        }]
    }
Essentially:
- Define a variable: 
_fsChartIDto keep track of the which chart is in fullscreen mode. For me, this was defined as a global variable within the module it was needed in. - Update this variable to the correct chart id whenever a chart enters full screen mode.
 - If a chart fails the fullscreen test, check and see if its the same ID as the chart that entered fullscreen.
- If so, reset the 
_fsChartIDvariable and do what you need - Else, return false as normal
 
 - If so, reset the 
 
Note that I simply called this.redraw() because my issue was related to the chart not redrawing correctly when exiting full screen.
        Bernardo Marques
        
- 925
 - 2
 - 10
 - 33
 
        laventnc
        
- 175
 - 13
 
- 
                    is there any sample you could provide on jsfiddle ? – Afsanefda Oct 06 '19 at 11:05
 - 
                    was the above code not sufficient ? could you provide me with a jsfiddle of your setup and i can add the required code to it. – laventnc Oct 10 '19 at 14:37