Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/430.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Windows Phone 7中将HTML内容适配到web浏览器_Javascript_C#_Html_Windows Phone 7 - Fatal编程技术网

Javascript 如何在Windows Phone 7中将HTML内容适配到web浏览器

Javascript 如何在Windows Phone 7中将HTML内容适配到web浏览器,javascript,c#,html,windows-phone-7,Javascript,C#,Html,Windows Phone 7,我正在尝试根据html内容的大小调整浏览器的大小。我尝试了以下代码 private void WebBrowser_OnLoaded(object sender, RoutedEventArgs e) { String htmlHead = "<html><head><meta charset='UTF-8'/><meta name=\"viewport\" content=\"width='480', initial-scale='1'\"/&

我正在尝试根据html内容的大小调整浏览器的大小。我尝试了以下代码

private void WebBrowser_OnLoaded(object sender, RoutedEventArgs e)
{
    String htmlHead = "<html><head><meta charset='UTF-8'/><meta name=\"viewport\" content=\"width='480', initial-scale='1'\"/>{0}</head><body onload=\"ResizeWebBrowser()\"><center>{1}</center></body></html>";
    myWebView.NavigateToString(String.Format(htmlHead, getScript(), getHTMLContent()));
    myWebView.IsScriptEnabled = true;
    myWebView.ScriptNotify += new EventHandler<NotifyEventArgs>(WebBrowser_ScriptNotify);
}

private void WebBrowser_ScriptNotify(object sender, NotifyEventArgs e)
{
    if (!string.IsNullOrEmpty(e.Value) && !(e.Value == ""))
    {
        this.myWebView.Height = double.Parse(JsonParsing(e.Value));
        myWebView.UpdateLayout();
    }
}

private string getScript()
{
    string script = "<script>";
    script += "function ResizeWebBrowser()";
    script += "{";
    script += "var _renderedHeight=document.body.firstChild.offsetHeight * 0.66;";
    script += "var _json = '{\"rendered_height\" : '+_renderedHeight+'}';";
    script += "window.external.notify(_json)";
    script += "}";
    script += "ResizeWebBrowser();";
    script += "</script>";
    return script;
}

public string getHTMLContent()
{
    StringBuilder htmlBody = new StringBuilder();
    htmlBody.Append("<table cellpadding=\"0\" cellspacing=\"0\" width=\"704\" height=\"484\" background=\"https://known.com/img/back/123456.jpg\" style=\"background-repeat: no-repeat; background-position: center;\">");
    htmlBody.Append("<tr>");
    htmlBody.Append("<td valign=top>");
    htmlBody.Append("<div style=\"position: absolute;\">");
    htmlBody.Append("<div style=\"position: absolute; display: table; width: 132px; height: 132px; top: 44px; left: 44px; z-index:0;\">");
    htmlBody.Append("<img src=\"https://known.com/img/icon/87654.jpg\" width=\"100%\" height=\"100%\"/>");
    htmlBody.Append("</div>");
    htmlBody.Append("<div style=\"position: absolute; display: table; width: 704px; height: 484px; top: 0px; left: 0px; z-index:0; \">");
    htmlBody.Append("<img src=\"https://known.com/img/icon/234255.jpg\" width=\"100%\" height=\"100%\"/>");
    htmlBody.Append("</div>");
    htmlBody.Append("<div style=\"position: absolute; display: table; width: 440px; height: 264px; top: 184px; left: 184px; z-index:0;  font-family:times;  font-size:14px;  color:#FFFFFF; \" align=\"center\">");
    htmlBody.Append("<div style=\"display: table-cell;vertical-align: middle;\">");
    htmlBody.Append("</div>");
    htmlBody.Append("</div>");
    htmlBody.Append("</div>");
    htmlBody.Append("</td>");
    htmlBody.Append("</tr>");
    htmlBody.Append("</table>");
    return htmlBody.ToString();
}
private void WebBrowser_已加载(对象发送方,路由目标e)
{
字符串htmlHead=“{0}{1}”;
myWebView.NavigateToString(String.Format(htmlHead,getScript(),getHTMLContent());
myWebView.IsScriptEnabled=true;
myWebView.ScriptNotify+=新的事件处理程序(WebBrowser_ScriptNotify);
}
私有void WebBrowser_ScriptNotify(对象发送方,NotifyEventArgs e)
{
如果(!string.IsNullOrEmpty(e.Value)&&&!(e.Value==“”)
{
this.myWebView.Height=double.Parse(JsonParsing(e.Value));
myWebView.UpdateLayout();
}
}
私有字符串getScript()
{
字符串脚本=”;
脚本+=“函数大小调整WebBrowser()”;
脚本+=“{”;
脚本+=“var _renderedHeight=document.body.firstChild.offsetHeight*0.66;”;
脚本+=“var\u json='{\'呈现的高度\':'+\u呈现的高度+'}';”;
脚本+=“window.external.notify(_json)”;
脚本+=“}”;
脚本+=“ResizeWebBrowser();”;
脚本+=“”;
返回脚本;
}
公共字符串getHTMLContent()
{
StringBuilder htmlBody=新的StringBuilder();
htmlBody.Append(“”);
htmlBody.Append(“”);
htmlBody.Append(“”);
htmlBody.Append(“”);
htmlBody.Append(“”);
htmlBody.Append(“”);
htmlBody.Append(“”);
htmlBody.Append(“”);
htmlBody.Append(“”);
htmlBody.Append(“”);
htmlBody.Append(“”);
htmlBody.Append(“”);
htmlBody.Append(“”);
htmlBody.Append(“”);
htmlBody.Append(“”);
htmlBody.Append(“”);
htmlBody.Append(“”);
htmlBody.Append(“”);
返回htmlBody.ToString();
}
现在我可以调整浏览器的大小了。但现在我面临一个问题。 也就是说,内容将从浏览器中删除。如果双击该页面,则只有内容适合浏览器。 请让我知道任何适合浏览器内容的方法


请使用一些屏幕快照shi@csharpwinphonexaml更好地解释您的问题。。我已附上我的样本项目。请下载它,让我以任何方式来解决我的问题。