0
我想使用Wpf webBrowser控件來渲染數學方程。 我已經下載了MathJax,並將其包含在我的Visual studio項目中。wpf webBrowser NavigateToString腳本錯誤
我試過加載MathJax示例中的一個。這是HTML代碼我使用:
<!DOCTYPE html>
<html>
<head>
<title>MathJax MathML Test Page</title>
<!-- Copyright (c) 2010-2012 Design Science, Inc. -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<script type="text/javascript" src="MathJax-Reduced/unpacked/MathJax.js?config=TeX-AMS-MML_HTMLorMML-full"></script>
</head>
<body>
<p>
When
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mi>a</mi><mo>≠</mo><mn>0</mn>
</math>,
there are two solutions to
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mi>a</mi><msup><mi>x</mi><mn>2</mn></msup>
<mo>+</mo> <mi>b</mi><mi>x</mi>
<mo>+</mo> <mi>c</mi> <mo>=</mo> <mn>0</mn>
</math>
and they are
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<mi>x</mi> <mo>=</mo>
<mrow>
<mfrac>
<mrow>
<mo>−</mo>
<mi>b</mi>
<mo>±</mo>
<msqrt>
<msup><mi>b</mi><mn>2</mn></msup>
<mo>−</mo>
<mn>4</mn><mi>a</mi><mi>c</mi>
</msqrt>
</mrow>
<mrow> <mn>2</mn><mi>a</mi> </mrow>
</mfrac>
</mrow>
</math>
</p>
</body>
</html>
一切正常用下面的代碼:
string curDir = Directory.GetCurrentDirectory();
this.webBrowser1.Navigate(new Uri(String.Format("file:///{0}/test-1.html", curDir)));
但如果我嘗試這種代碼:
string s = File.ReadAllText(Directory.GetCurrentDirectory() + "\\test-1.html");
this.webBrowser1.NavigateToString(s);
,我收到了腳本錯誤:
An error has occurred in the script on this page.
Line: 1
Char: 1
Error: Syntax Error
Code: 0
URL: about:MathJax-Reduced/unpacked/MathJax.js?config=TeX-AMS-MML_HTMLorMML-full
什麼是w榮?這將是真正有用的東西類似的最後一個代碼,所以我可以避免保存一個文件只是爲了加載它...
我已經tryed添加的絕對路徑: '文件:// C $ /用戶/達維德/文檔/視頻%20Studio%202010 /項目/試驗MathJax-1 /測試-MathJax-1 /斌/ Debug/MathJax-Reduced/unpacked/MathJax.js?config = TeX-AMS-MML_HTMLorMML-full' \ n它不渲染數學。 – 2013-05-02 20:42:27
我試過使用: 'file://127.0.0.1/C$/Users/Davide/Documents/Visual%20Studio%202010/Projects/Test-MathJax-1/Test-MathJax-1/bin/Debug/ MathJax-Reduced/unpacked/MathJax.js?config = TeX-AMS-MML_HTMLorMML-full' 這給了我錯誤: '此頁面上的腳本發生錯誤。 行:字符:錯誤:\t無法獲取財產 'IMG' 的值:對象爲空或未定義 代碼:網址:\t文件://127.0.0.1/C$/ Users/Davide/Documents/Visual%20Studio%202010/Projects/Test-MathJax-1/Test-MathJax-1/bin/Debug/MathJax-Reduced/unpacked/jax/output/HTML-CSS/imageFonts.js' – 2013-05-02 20:52:31
The 'MathJax-Reduced'表明你已經刪除了MathJax發行版的一部分,可能是圖像字體('font/HTML-CSS/TeX/png'文件夾),因爲它們構成了MathJax佔用的大部分空間。請注意,嘗試加載圖像字體包時發生失敗,這表明它們已被刪除。如果你沒有安裝圖像字體,你需要通過在配置的「HTML-CSS」部分設置'imageFont:null'來通知MathJax。 – 2013-05-03 11:12:30