简体   繁体   English

jQuery-ScrollTop在Chrome扩展程序中不起作用

[英]JQuery - ScrollTop not working in Chrome Extension

I've been trying to figure this out for a while now, but I'm at my wit's end and have given up all hope. 我已经尝试了好一阵子了,但是我已经不知所措了,放弃了所有希望。

Here is my unpacked chrome extension: nexrem.com/test/extension-test2 - Copy.zip 这是我解压缩的Chrome扩展程序: nexrem.com/test/extension-test2-Copy.zip

Exhibit A: 展览A:

  • Navigate into the template folder 导航到模板文件夹
  • run test.html in Chrome 在Chrome中运行test.html
  • Click on the "Footer link" 点击“页脚链接”
  • Observe it scroll correctly to the footer 观察它正确滚动到页脚

Exhibit B: Currently, the extension basically replaces the entirety of html on the page. 图表B:目前,该扩展程序基本上替代了页面上的整个html。

  • Install the unpacked extension 安装解压缩的扩展
  • Go to some website (for the sake of testing, one that isn't filled with all sorts of scripts. or just make a local blank html file) 转到某个网站(为了进行测试,该网站没有各种脚本,或者只是制作了一个本地空白html文件)
  • Click the extension icon in chrome 点击Chrome中的扩展程序图标

You will see the exact same page as when you ran just the test.html ;however, the jquery scrolling no longer works . 您将看到与仅运行test.html时完全相同的页面;但是, jQuery滚动不再起作用 I fail to understand why. 我不明白为什么。

If someone can explain this to me, assist in a solution or at least point in the right direction, I'd greatly appreciate it! 如果有人可以向我解释这一点,提供解决方案或至少指出正确的方向,我将不胜感激!

According to load 根据负载

jQuery uses the browser's .innerHTML property to parse the retrieved document and insert it into the current document. jQuery使用浏览器的.innerHTML属性解析检索到的文档并将其插入到当前文档中。 During this process, browsers often filter elements from the document such as <html> , <title> , or <head> elements. 在此过程中,浏览器经常从文档中过滤元素,例如<html><title><head>元素。 As a result, the elements retrieved by .load() may not be exactly the same as if the document were retrieved directly by the browser . 结果,通过.load()检索的元素可能与通过浏览器直接检索的文档不完全相同

And after digging into your html code after you click the browser action, it seems the body tag is not included. 在单击浏览器操作后深入研究html代码后,似乎没有包含body标签。

You can use the following code instead load 您可以使用以下代码代替load

    var template = chrome.extension.getURL('template/test.html');
    console.log(template);

    $.get(template, function(data) {
        document.open();
        document.write(data);
        document.close();
        $.cache = {};
    }, "text");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM