Click here to Skip to main content
15,903,203 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
XML
hi,
i have div wich a apeare a google map and i create a link full screen when i click i have what i wont but when i close full screen the div stil have width and height i have give onclik this is o code plllz help me and sorry for my bad english

 <style>
        #map-canvas
        {
            height: 520px;
            width:1100px;
            border: 2px solid #326195;
            margin: 5px;

        }
</style>

<script>
        function changeWidth() {
            var e1 = document.getElementById("map-canvas");
            e1.style.width = "100%";
            e1.style.height = "100%";
        }
        //foction plein ecran
        var element, fullscreenbtn;
        function intializePlayer() {
            element = document.getElementById('map-canvas');
            fullscreenbtn = document.getElementById('fullscreenbtn');
            // Add event listeners
            fullscreenbtn.addEventListener('click', toggleFullScreen, false);
        }
        window.onload = intializePlayer;

        function toggleFullScreen() {
            if (element.requestFullScreen) {
                element.requestFullScreen();
            } else if (element.webkitRequestFullScreen) {
                element.webkitRequestFullScreen();
            } else if (element.mozRequestFullScreen) {
                element.mozRequestFullScreen();
            }
        }
    </script>
  <form id="form1"  runat="server">


               <a href="#" id="fullscreenbtn" style="z-index: 10;">plein ecran</a>
           
        
        <div id="map-canvas">
         
        </div>
</form>
Posted

1 solution

The problem is that the API hooks for request and cancel full screen are different; it is not a toggle on it's own.

You need to make some minor modifications:

JavaScript
var fullScreen = false;
function toggleFullScreen() {
            if (element.requestFullScreen) {
                if(fullScreen){
                   element.CancelFullScreen();
                   fullScreen = false;}
                else{
                   element.requestFullScreen();
                   fullScreen = true;
                }
            } else if (element.webkitRequestFullScreen) {
                if(fullScreen){
                   element.webkitCancelFullScreen();
                   fullScreen = false;
                }
                else{
                   element.webkitRequestFullScreen();
                   fullScreen = true;
                }
            } else if (element.mozRequestFullScreen) {
                if(fullScreen){
                   element.mozCancelFullScreen();
                   fulLscreen = false;
                }
                else{
                   element.mozRequestFullScreen();
                   fullScreen = true; 
                }
            }
        }


For more information:
https://developer.mozilla.org/en-US/docs/Web/API/Document/mozCancelFullScreen[^]
 
Share this answer
 
v3
Comments
Member 11573837 13-Apr-15 9:38am    
hi,
thank you, but i didn't understand you,
i have div which have height:520px and width:1100px; when i click full screen i set height and width to 100% when i quit full screen i want have height:520px and width:1100px and thank you one more time
Nathan Minier 13-Apr-15 9:41am    
Yes sir, and with your style sheet that should work just fine. You need to run element.CancelFullScreen() to turn off the full-screen effect.
Member 11573837 13-Apr-15 9:47am    
like this
if(element.CancelFullScreen())
{
element.style.width = "520px";
element.style.height = "1100px";
}
Member 11573837 13-Apr-15 9:49am    
sorry doesn't work how can i do it plz
Nathan Minier 13-Apr-15 9:57am    
Is it not working, or not resetting to your stylesheet parameters?

Did you make sure to include the global fullScreen variable?

Paste the current script, please.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900