使用WebKit.net加載HTML編輯器


關於webkit.net使用請看這里http://www.cnblogs.com/linyijia/p/4045333.html

nicedit編輯器請到這里下載http://www.nicedit.com/download.php

private void Form1_Load(object sender, EventArgs e)
        {
            string url = String.Format(@"file:\\\{0}nicedit\index.html", AppDomain.CurrentDomain.BaseDirectory);
            url = url.Replace("\\", "/").Replace(" ","%20");
            webKitBrowser1.Navigate(url);
        }

  需要把路徑修改一下,空格也要轉碼

以nicedit為例,以下是index.html代碼,里面新增了兩個方法,getData(取值)、setData(賦值)

<html>
<head>
	<title></title>
</head>
<body style="padding:0;margin:0">
<div id="sample">
<script src="nicEdit.js" type="text/javascript"></script>
<script type="text/javascript">
bkLib.onDomLoaded(function() {
	nic=new nicEditor({fullPanel : true}).panelInstance('area2');
	ndinstance = nic.nicInstances[0]; 
});
		function setData(html) {//設置html
			ndinstance.setContent(html);
        }
		function getData(){//獲取html
			return ndinstance.getContent();
		}
</script>

<textarea style="width:1000px;height:740px" id="area2"></textarea>

</div>


</body>
</html>

  c#使用代碼進行取值和賦值

賦值(因為InvokeScriptMethod這方法沒法帶參數,所以改用以下方法):
webKitBrowser1.StringByEvaluatingJavaScriptFromString("setData('sdfsd')");

  

取值:
MessageBox.Show(webKitBrowser1.Document.InvokeScriptMethod("getData").ToString()); 

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM