修复 chrome 缩放问题
如何在不同的站点上设置不同的缩放级别。我可以使用 window.location 从 chrome 地址栏获取 url 并为该特定站点设置缩放级别 我如何修改此代码以使用 window.location 或 window.location.href
function zoom(zp) {
page = document.getElementsByTagName('html')[0]
if (page != null) {
page.style.zoom = zp + "%";
}
}
chrome.extension.sendRequest(
{"type": "setZoom"},
function(zp) {
zoom(zp);
}
);
how can i set different zoom levels on different site. can i use window.location to get the url from the chrome address bar and set a zoom level for that specific site how can i modify this code to use window.location or window.location.href
function zoom(zp) {
page = document.getElementsByTagName('html')[0]
if (page != null) {
page.style.zoom = zp + "%";
}
}
chrome.extension.sendRequest(
{"type": "setZoom"},
function(zp) {
zoom(zp);
}
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,请注意,Chrome 已经处理由 C+ + 和 C+ - 设置的每个域缩放级别,但这与 html.style.zoom 不同。
您当然可以做您想做的事情,但是您需要将内容脚本注入到您想要操作其 CSS 的页面中。然后,您可以从扩展的另一部分向该注入的脚本发送消息并获得所需的结果。您可以通过(例如)在扩展程序的 localStorage 中存储 {url: ZoomLevel} 哈希表来跟踪每个 URL 的缩放级别。
请注意,使用 html.style.zoom 属性存在问题:例如,它不适用于 iframe。这里有关于此的广泛讨论:http://crbug.com/30583
Firstly, note that Chrome already handles setting per-domain zoom levels set by C+ + and C+ -, but this is different from the html.style.zoom.
You can certainly do what you're trying to, but you'll need to inject a content script into the page whose CSS you want to manipulate. Then, you can send messages to that injected script from another part of your extension and get the desired result. You can keep track of zoom levels per URL by (for example) storing a {url: zoomLevel} hash table in your extension's localStorage.
Note that there are problems using the html.style.zoom property: for example, it doesn't work on iframes. There's an extensive discussion about this here: http://crbug.com/30583