积极答复者
webBrowser如何为网页中的高级编辑框设置value

问题
-
webBrowser如何为下图中的高级编辑框设置value:
部分HTML如下:
</td>
</tr>
<tr>
<td colspan="2" align="center" valign="top" class="bk">
<script type="text/javascript" src="./ckeditor/ckeditor.js"></script>
<textarea cols="80" name="gently_editor" id="gently_editor" rows="10"></textarea>
<script type="text/javascript">
CKEDITOR.replace('gently_editor'); //content为textarea的id
if(content=="[object]") content="";
document.getElementById("gently_editor").value=content;
</script>
<!--<textarea name="gently_editor" id="gently_editor" style="display:none" ></textarea>
<iframe id="frm" frameborder="0" marginheight="0" marginwidth="0" scrolling="No" width="690" height="460" src="Editor/Edit/editor.htm"></iframe>-->
</td>
</tr>
<tr>
<td colspan="2" align="left" valign="top" class="bk">
</td>
- 已编辑 求知与释疑 2013年5月18日 3:36
答案
-
// 获得Iframe中的html文档 HtmlDocument doc= webBrowser1.Document.Window.Frames[0].Document; // 获得Iframe中的body元素 HtmlElement bodyele =doc.GetElementsByTagName("body"); // 对body元素内容赋值 bodyele.InnerHtml ="<p>abcdf</p>";
试试这个代码看看的If my post is helpful,please help to vote as helpful, if my post solve your question, please help to make it as answer. my sample
-
我曾经这样试过:在该DocumentCompleted事件中写上“MessageBox.show("success");”,然后人为转到该网页,结果三次弹出MessageBox,应该就可以说明DocumentCompleted事件响应了三次吧。
你可以尝试定义一个全局类公共变量(比如叫flag,默认是false,表示第一次加载)。
然后在该事件中用if判断,如果是false才做你要的事情,最后在if中设置变量为true。
If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & Cats
Found any spamming-senders? Please report at: Spam Report- 已标记为答案 求知与释疑 2013年8月11日 9:12
全部回复
-
你这是WinForm还是Web的问题,说清楚我可以帮助你移动到对应的板块以便获取更多的帮助。
同时说明一下如果不设置会怎样?
If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & Cats
Found any spamming-senders? Please report at: Spam Report -
在IE等浏览器中打开有问题吗?
If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & Cats
Found any spamming-senders? Please report at: Spam Report -
或许你应该考虑innerText而不是value,因为value是属性,而textarea没有这个属性。
If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & Cats
Found any spamming-senders? Please report at: Spam Report- 已标记为答案 Bob ShenModerator 2013年6月4日 8:50
- 取消答案标记 求知与释疑 2013年6月11日 9:09
-
我想你应该是想通过WebBrowser这个控件来对页面进行操作的。整个HTML文档以及其包含的各个HTML元素,都和一个个HtmlDocument、HtmlElement之类的.Net对象对应。因此只要找到这个“文本输入框”对应的HtmlElement对象。
相信下面的文章可以帮助到你,你可以按照文章的步骤来实现你的需求:
http://smalldust.cnblogs.com/archive/2006/03/08/345561.html
If my post is helpful,please help to vote as helpful, if my post solve your question, please help to make it as answer. my sample
- 已标记为答案 Bob ShenModerator 2013年6月4日 8:50
- 取消答案标记 求知与释疑 2013年6月11日 9:09
-
WebBrowser只是html的一个容器了,你可以使用HtmlDocument这个类来对WebBrowser控件内的html进行操作的,你首先要获得你操作的html元素,然后对其设置,你的innerText不能设置,你可以设置它的innerHtml来实现的了:具体代码如下:
// 获得TextArea标签,类似js的写法了 HtmlElement textarea = webBrowser.Document.GetElementById("gently_editor") // 设置textarea内的内容,字符串你可以根据的需要设置,也可以设置为html字符串,如"<p>Hello World</p>" textarea.InnerHtml="hello";
If my post is helpful,please help to vote as helpful, if my post solve your question, please help to make it as answer. my sample
-
-
你要操作的是嵌入在iframe里的内容吗? 主要你要先获得里面的textarea元素的,我上面的代码你调试下是否可以获取到的元素是否为空了?
If my post is helpful,please help to vote as helpful, if my post solve your question, please help to make it as answer. my sample
- 已建议为答案 Learning hard 2013年6月12日 11:13
- 取消建议作为答案 求知与释疑 2013年6月13日 7:17
-
HtmlElement body= webBrowser.Document.GetElementsByTagName ("body") string text =dody.InnerHtml;
可以采用这样的代码If my post is helpful,please help to vote as helpful, if my post solve your question, please help to make it as answer. my sample
- 已建议为答案 Learning hard 2013年6月12日 11:13
-
GetElementsByTagName 这个方法获得是一个集合了,你可以通过foreach来遍历这个集合来找你需要的body元素的了,你可以以className来进行区别,例如:
if (webBrowser1.Document != null) { HtmlElementCollection elems = webBrowser1.Document.GetElementsByTagName("body"); foreach (HtmlElement elem in elems) { String nameStr = elem.GetAttribute("class"); if (nameStr != null && nameStr == "cke_show_borders") { // 此时的元素就是你要的body元素了 string content =elem.InnerHtml; } } }
If my post is helpful,please help to vote as helpful, if my post solve your question, please help to make it as answer. my sample
-
你输入的内容控件是不是iframe中的body内容了? 如果那样的话,我觉得你肯定修改了不是iframe中body内容,你可能修改了整个页面的body内容才会导致你的控件丢失了,操作iframe内的网页内容应该使用下面的方式:
HtmlDocument doc= webBrowser1.Document.Window.Frames["frameMain"].Document;//获取iframe中body元素 HtmlElement el= doc.GetElementById("drpXingbie"); el.InnerText="abc";;
更多内容参考下面的文章:
http://www.cnblogs.com/ado-geek/archive/2012/05/17/2506096.html
If my post is helpful,please help to vote as helpful, if my post solve your question, please help to make it as answer. my sample
-
// 获得Iframe中的html文档 HtmlDocument doc= webBrowser1.Document.Window.Frames[0].Document; // 获得Iframe中的body元素 HtmlElement bodyele =doc.GetElementsByTagName("body"); // 对body元素内容赋值 bodyele.InnerHtml ="<p>abcdf</p>";
试试这个代码看看的If my post is helpful,please help to vote as helpful, if my post solve your question, please help to make it as answer. my sample
-
谢谢您,成功了。
补充一句:
GetElementsByTagName返回的是一个数组,获取第一个元素应该:)
HtmlElementbodyele =doc.GetElementsByTagName("body")[0];
If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & Cats
Found any spamming-senders? Please report at: Spam Report -
Learning hard:)
我点击你的"my sample"貌似登陆是我的账号,并非你的……如果你要让我们看到你的Sample,建议直接黏贴Url:你看看这样如何?
方便的话加QQ(扫描我的头像),想和你做朋友,你蛮厉害的;)
If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & Cats
Found any spamming-senders? Please report at: Spam Report- 已编辑 ThankfulHeartModerator 2013年6月13日 9:24
-
索引异常,检查你的索引是否在预定的范围内。
If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & Cats
Found any spamming-senders? Please report at: Spam Report -
情况是这样的:那个网页分为几个Frames,所以加载完成DocumentCompleted事件自然就会响应三次,而我要操作的输入框是在最后一个Frame中的(索引是有的),所以就会在前两个Frame加载时出错。请问如何解决这种问题?
你直接写在DocumentCompleted事件中应该可以吧——全部加在完毕了。If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & Cats
Found any spamming-senders? Please report at: Spam Report -
我曾经这样试过:在该DocumentCompleted事件中写上“MessageBox.show("success");”,然后人为转到该网页,结果三次弹出MessageBox,应该就可以说明DocumentCompleted事件响应了三次吧。
你可以尝试定义一个全局类公共变量(比如叫flag,默认是false,表示第一次加载)。
然后在该事件中用if判断,如果是false才做你要的事情,最后在if中设置变量为true。
If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & Cats
Found any spamming-senders? Please report at: Spam Report- 已标记为答案 求知与释疑 2013年8月11日 9:12