gpt4 book ai didi

javascript - 如何重置 UWP WebView 的内容缩放因子

转载 作者:行者123 更新时间:2023-11-30 15:33:45 25 4
gpt4 key购买 nike

我正在尝试将 c# UWP 中的 webview 的内容缩放因子重置为 1 或 100%。

我的问题是如何做到这一点?

  • 有没有办法告诉 webview 本身通过 c# 缩减到 1.0?

喜欢 webView.ContentScale = 1.0;

  • 我必须在 html 中调用什么才能告诉它缩放回 100%?

就像我会这样做来执行点击

webView.InvokeScriptAsync("eval", new string[] { "document.elementFromPoint(" + 555 + ", " + 355 + ").click();" });

如果你知道如何在 html/js 中重置缩放因子,它也会对我有帮助。我会通过评估添加该代码并调用它。

信息:Microsoft Edge 渲染引擎用于这些 WebView 。

我不想只重新加载页面,因为可能有一些用户更改,然后这些更改可能会丢失。

来自德国的亲切问候。

最佳答案

is there a way to tell the webview itself to scale back to 1.0 via c#?

目前恐怕没有这样的方法可以直接设置WebView的内容规模。

It would also help me if you know how to reset the zoomfactor in html / js. I would add that code via evaluation and call it.

如你所想,我们可以在WebView加载的页面上添加一个Javascript函数,并通过InvokeScriptAsync调用该函数。方法。我们可以设置zoom该函数中的样式属性以根据需要重置缩放系数。例如,我们将以下 HTML 加载到 WebView,并创建了一个 ZoomFunction:

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript">
function ZoomFunction(Percentage) {
var mybody = document.getElementById("mybody");
mybody.style.zoom = Percentage + "%";
}
</script>
</head>
<body id="mybody" style="margin:0px;padding:0px; overflow:hidden;zoom:50%">
This content is shown for zoom in and out.
</body>
</html>

这样我们就可以通过如下调用脚本将内容缩放到 100%:

 await MyWebView.InvokeScriptAsync("eval", new string[] { "ZoomFunction(100);" });

更多详情请引用How to zoom in/out the content in WebView in Universal Windows Platform .

关于javascript - 如何重置 UWP WebView 的内容缩放因子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41894616/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com