开发者

fix chrome zoom issues

开发者 https://www.devze.com 2023-03-16 09:08 出处:网络
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 us

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开发者_如何学JAVA')[0]
    if (page != null) {
        page.style.zoom = zp + "%";
    }
}

chrome.extension.sendRequest(
    {"type": "setZoom"},
    function(zp) {
        zoom(zp);
    }
);


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

0

精彩评论

暂无评论...
验证码 换一张
取 消