使用chrome扩展名移至页面顶部 [英] Move to top of page with chrome-extension
问题描述
有没有人知道一个命令将滚动到顶部/跳转到顶部功能绑定到一个按钮?
我发现了一些更花哨的东西,有一个更简单的版本:
https://chrome.google.com/extensions/ detail / chiikmhgllekggjhdfjhajkfdkcngplp
非常感谢。
那么,你可以做到以下几点,滚动到X = 0,Y = 0,这就是它 https://developer.mozilla.org/en/window.scroll window.scroll(0,0 );
如果您想将其与Google Chrome扩展程序挂钩,您只需创建JavaScript文件并将其注入到您的页面:
background.html
chrome.browserAction.onClicked.addListener(function(tab){
chrome.tabs.executeScript(tab.id,{code:'window.scroll(0,0);'}) ;
});
manifest.json
确保您拥有标签权限和浏览器操作:
...
...
browser_action:{
default_icon:some_icon.png,
},
permissions:[
tabs,
http:// * / *
,
...
...
我没有测试过,但它会让你知道如何通过浏览器操作按钮通过扩展将命令从Chrome发送到网站。一旦你点击那个按钮,它将执行一个脚本将该页面滚动到top.absolute顶部。
does anybody know a command to bind "scroll to top"/ "jump to top" function to a button?
I found something more fancy, but would like to have a more simple version: https://chrome.google.com/extensions/detail/chiikmhgllekggjhdfjhajkfdkcngplp
Much appreciated.
Well, you can just do the following, scroll to X=0, and Y=0, and thats it https://developer.mozilla.org/en/window.scroll
window.scroll(0, 0);
If you want to hook that up to Google Chrome Extensions, all you need to do is create a JavaScript file and inject it to your page:
background.html
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.executeScript(tab.id, {code: 'window.scroll(0, 0);'});
});
manifest.json
Make sure you have the tabs permission and browser action:
...
...
"browser_action": {
"default_icon": "some_icon.png",
},
"permissions": [
"tabs",
"http://*/*"
],
...
...
I havn't tested that, but it will give you an idea how to send a command from Chrome to Website through extensions via browser action button. Once you click on that button, it will execute a script to scroll that page to the top.absolute top.
这篇关于使用chrome扩展名移至页面顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!