最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Enabling browser scroll bars after window.open with scrollbars=no - Stack Overflow

programmeradmin3浏览0评论

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?

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?

Share Improve this question asked May 15, 2013 at 10:08 Dan CookDan Cook 2,0727 gold badges31 silver badges54 bronze badges 3
  • Thanks for your post. I have resolved my problem due to your post. (At least for IE) – Kamesh Jungi Commented Oct 16, 2013 at 7:00
  • I don't think you can disable scrollbar in Chrome with that code, so you just need to find a fix for Firefox. – Chirag Bhatia - chirag64 Commented Jul 25, 2014 at 14:38
  • Try <body scroll="false"> and javascript not good attribute scroll. – KingRider Commented Aug 3, 2016 at 14:27
Add a ment  | 

3 Answers 3

Reset to default 2

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.

Since you add js for IE I assume you can change the way displayed page works. In that case I would try to put the contents of the opened window in div, and set its style to something like: height: 200px; overflow: auto;

Actually I tried with different browser, If you have fixed requirement about height, what you can do is wrap all the content of example.html in a specific div with the attached css like overflow:auto;height:200px. I will show you the whole code.

<body>
<div style="overflow:auto;height:200px;">
    Your HTML code       
</div>
</body>

put it into example.html. Height you can get from your code window.open("example.html", "name", "resizable=1,scrollbars=no,width=500,height=200");.

This is not the the actual solution but it will solve your problem in every browser.

Hope this help.

发布评论

评论列表(0)

  1. 暂无评论