如何在移动设备上禁用UWP WebView中的内容?
我有一个html页面,其中有一个不断变化的div块 当新文本出现在此块中时,字体大小开始减小, 这样整个文本就可以放在如何在移动设备上禁用UWP WebView中的内容?,webview,uwp,Webview,Uwp,我有一个html页面,其中有一个不断变化的div块 当新文本出现在此块中时,字体大小开始减小, 这样整个文本就可以放在WebView中 我希望字体大小保持不变,但会在WebView中显示一个滚动条 问题是仅在移动设备上复制 Html页面的代码: <!DOCTYPE html> <html> <head> <title>Problem with Page</title> </head> <b
WebView
中
我希望字体大小保持不变,但会在WebView
中显示一个滚动条
问题是仅在移动设备上复制
Html页面的代码:
<!DOCTYPE html>
<html>
<head>
<title>Problem with Page</title>
</head>
<body>
<script>
AddText = function (v) {
var div = document.getElementById('TextContainer');
div.innerHTML = div.innerHTML + v;
};
</script>
<div style="font-size: 250%;" id="TextContainer"></div>
<input type="submit" value="button" onClick="AddText(this.value)">
</body>
</html>
页面问题
AddText=函数(v){
var div=document.getElementById('TextContainer');
div.innerHTML=div.innerHTML+v;
};
Xaml页面的代码:
<Page
x:Class="EvidentCalculator.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:EvidentCalculator"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<WebView Margin="3,0,3,0" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Top" Height="150" x:Name="WebContainer"/>
<Button Grid.Row="1" Content="Invoke script!" Click="BtnClick"/>
</Grid>
</Page>
代码隐藏:
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
InitializeComponent();
Loaded+=OnLoad;
}
private async void OnLoad(object sender, RoutedEventArgs e)
{
//TODO Need some code to load html into WebView!!!
}
private async void BtnClick(object sender, RoutedEventArgs e)
{
await WebContainer.InvokeScriptAsync("AddText", new[] { "Some test text" });
}
}
//
///可以单独使用或在框架内导航到的空页。
///
公共密封部分类主页面:第页
{
公共主页()
{
初始化组件();
已加载+=已加载;
}
私有异步void OnLoad(对象发送方,RoutedEventArgs e)
{
//TODO需要一些代码将html加载到WebView!!!
}
私有异步无效BtnClick(对象发送方,路由目标)
{
wait WebContainer.InvokeScriptAsync(“AddText”,new[]{“Some test text”});
}
}
我已经测试了您的代码并复制了您的问题。问题是,添加“按钮”文本时,div
块被拉伸,并且没有自动换行。为了使div
块能够正常工作,您可以使用wordbreak:break all
创建样式
<body>
<script>
AddText = function (v) {
var div = document.getElementById('TextContainer');
div.innerHTML = div.innerHTML + v;
};
</script>
<div style="font-size: 250%; word-break:break-all" id="TextContainer"></div>
<input type="submit" value="button" onClick="AddText(this.value)" />
<button id="btnClick" type="button" value="Some test" onclick="AddText(this.value)">Click Me </button>
</body>
解决的方法是ViewBox。我已经尝试添加div块的
innerText
。但我无法复制你的问题。请您分享更多关于html页面的详细信息。@NicoZhu MSFT我添加了一些代码来解释我的问题。不幸的是,这不是我需要的解决方案。我需要在一行与滚动条在WebView的文本。(没有包装)我忘了添加代码以更准确地再现我的问题,对不起。需要在Xaml-page的WebView中添加VerticalAlignment=“Top”Height=“150”。您可以通过将overflow-y:scroll
添加到div样式中来实现。您尝试过上述解决方法吗?如果您还有其他问题,请随时在这里发布。
<div style="font-size: 250%; overflow-y:scroll" id="TextContainer" ></div>