0
我有一個HTML頁面,在C#項目中生成。它的工作原理,當我在IE中打開此頁面。Windows.Forms.WebBrowser加載頁面本地SVG文件
<!DOCTYPE HTML>
<meta http-equiv='X-UA-Compatible' content='IE=10' />
<html lang='en'>
<head>
<title>TemplateSVG</title>
<script type='text/javascript' src='InterfaceSVG.js'></script>
</head>
<body style='margin: 0; overflow: hidden;'>
<div class="page-content">
<object id='idSVG' type='image/svg+xml' data='D:\Examples\ExampleFla.svg'></object>
</div>
</body>
</html>
我裝獲取文本在Web瀏覽器中
if (webBrowser.Document == null)
{
webBrowser.DocumentText = theHTMLtext;
}
else
{
webBrowser.Document.OpenNew(true);
webBrowser.DocumentText = theHTMLtext;
}
但文件InterfaceSVG.js沒有找到。
當我給完整路徑js文件src='D:\[Path]\InterfaceSVG.js'
JS腳本生成與getSVGDocument()
一致的異常。
var SvgDoc;
window.addEventListener('load', function() {
SvgDoc = document.getElementById("idSVG");
if (SvgDoc == null) { alert("error"); return; }
SvgDoc = SvgDoc.getSVGDocument(); // IE created Access Deny.
});
編輯: 嘗試插入來自js文件的文本。
<script>Text from InterfaceSVG.js </scipt>
但它產生相同的異常(訪問拒絕)對符合getSVGDocument()
我的文件夾中使用SVG文件和使用功能Navigate
代替DocumentText
保存的結果HTML頁面。現在它可以工作......但我不想在磁盤上寫任何東西。
string path = Path.GetDirectoryName(pathToSvgFile);
string file = "\\"+Path.GetFileNameWithoutExtension(pathToSvgFile);
string newfile = path + file;
File.WriteAllText(newfile, theHTMLtext);
webBrowser.Navigate(newfile);