Javascript 如何在禁用滚动的网站上启用滚动?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39360138/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 22:30:48  来源:igfitidea点击:

How to enable scrolling on website that disabled scrolling?

javascript

提问by CodeCamper

How to quickly re-enable scrolling on a website that has disabled scrolling with Javascript? window.scrollBy(0, 100) works fine just can't seem to figure out how to bind this to keys or mouse scroll.

如何在已禁用 Javascript 滚动的网站上快速重新启用滚动?window.scrollBy(0, 100) 工作正常只是似乎无法弄清楚如何将其绑定到键或鼠标滚动。

回答by designcise

In a browser like Chrome etc.:

在 Chrome 等浏览器中:

  1. Inspect the code (for e.g. in Chrome press ctrl + shift + c);
  2. Set overflow: visibleon body element (for e.g., <body style="overflow: visible">)
  3. Find/Remove any JavaScripts that may routinely be checking for removal of the overflowproperty:
    • To find such JavaScript code, you could for example, go through the code, or click on different JavaScript code in the code debugger console and hit backspaceon your keyboard to remove it.
    • If you're having trouble finding it, you can simply try removing a couple of JavaScripts (you can of course simply press ctrl + zto undo whatever code you delete, or hit refresh to start over).
  1. 检查代码(例如在 Chrome press 中ctrl + shift + c);
  2. overflow: visible在 body 元素上设置(例如,<body style="overflow: visible">
  3. 查找/删除任何可能经常检查overflow属性删除的 JavaScript :
    • 例如,要查找此类 JavaScript 代码,您可以浏览代码,或在代码调试器控制台中单击不同的 JavaScript 代码,然后敲击backspace键盘将其删除。
    • 如果您找不到它,您可以简单地尝试删除几个 JavaScript(您当然可以简单地按ctrl + z撤消删除的任何代码,或点击刷新重新开始)。

Good luck!

祝你好运!

回答by nerdgasms

adding overflow:visible !important;to the body element worked for me.

添加overflow:visible !important;到 body 元素对我有用。

回答by user1274820

Just thought I would help somebody with this.

只是想我会帮助某人解决这个问题。

Typically, you can just paste this in console.

通常,您可以将其粘贴到控制台中。

$("body").css({"overflow":"visible"});

$("body").css({"overflow":"visible"});

Or, the javascript only version:

或者,只有 javascript 版本:

document.body.style.overflow = "visible";

document.body.style.overflow = "visible";

回答by Future Sim

You can paste the following code to the console to scroll up/down using the a/z keyboard keys. If you want to set your own keys you can visit thispage to get the keycodes

您可以将以下代码粘贴到控制台以使用 a/z 键盘键向上/向下滚动。如果您想设置自己的密钥,您可以访问页面以获取密钥代码

function KeyPress(e) {
  var evtobj = window.event? event : e
  if (evtobj.keyCode == 90) {
    window.scrollBy(0, 100) 
  }
  if (evtobj.keyCode == 65) {
    window.scrollBy(0, -100) 
  }
}

document.onkeydown = KeyPress;

回答by Pranavjeet.Mishra

Select the Body using chrome dev tools (Inspect ) and change in css overflow:visible,

使用 chrome 开发工具(Inspect )选择 Body 并更改 css overflow:visible,

If that doesn't work then check in below css file if html, body is set as overflow:hidden , change it as visible

如果这不起作用然后检查下面的 css 文件,如果 html, body 设置为 overflow:hidden ,将其更改为可见

回答by kangaswad

Try this:

尝试这个:

window.onmousewheel = document.onmousewheel = null
window.ontouchmove = null 
window.onwheel = null 

回答by KingRider

Try ur code to add 'script' is last line or make test ur console (F12) enable scrolling

尝试您的代码添加“脚本”是最后一行或测试您的控制台(F12)启用滚动

<script>
(function() {
  for (div=0; div < document.querySelectorAll('div').length; div++) {
    document.querySelectorAll('div')[div].style.overflow = "auto";
  };
})();
</script>

回答by Andrew Roberts

One last thing is to check for Event Listeners > "scroll" and test deleting them.

最后一件事是检查事件侦听器>“滚动”并测试删除它们。

Even if you delete the Javascript that created them, the listeners will stick around and prevent scrolling.

即使您删除了创建它们的 Javascript,侦听器也会停留并阻止滚动。

回答by Idodo

I wanted to automatically re-enable scrolling on a website that disabled it. The way to do this in chrome is download "tapermonkey", and add this script:

我想在禁用它的网站上自动重新启用滚动。在 chrome 中执行此操作的方法是下载“tapermonkey”,并添加此脚本:

https://greasyfork.org/en/scripts/387702-scroll-bar-enabler