Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enabling browser scroll bars after window.open with scrollbars=no

I have an existing link which opens up a webpage in a new window with scrollbars disabled as follows:

<a onclick='window.open("example.html", "name", "resizable=1,scrollbars=no,width=500,height=200");' href='#'>Click to pop up without scroll bars</a>

For the sake of argument, I cannot change this window.open() code. I need to enable scroll bars after the window has been opened.

This works in IE using the following code:

 <script type="text/javascript">
    onload=function()
        {
    enableScrolling();
    }
    function enableScrolling()
    {
      document.body.scroll = "yes"; // IE 
    }
 </script> 

However this does not work in FireFox or Chrome.

According to this page, the following code should work for FireFox and Chrome but it does not (perhaps this worked in earlier versions?)

      document.documentElement.style.overflow='scroll';
      document.body.style.overflow='scroll';

Does anyone know if it is possible to enable scroll bars in FireFox and Chrome after the window has been opened with scrollbars disabled?

like image 971
Dan Cook Avatar asked May 15 '13 10:05

Dan Cook


1 Answers

Just like Nikunj Soni said, setting a height attribute to your body tag will help you solve the problem in every browser. What I will do differently is the following:

Instead of setting a fixed height, I would set height:100%, which enable you to open the popup also in different sizes than the original.

<body style="overflow:auto; height:100%;">
        The rest of your HTML code   
</body>

This is also not the best solution, but you are actually removing the restictions you get from the link.

Hope you find this answer helpful.

like image 132
Toteb99 Avatar answered Oct 13 '22 00:10

Toteb99