怎么获取iframe中的元素并修改其中的内容

时间:2022-12-20 21:07:58
<form id="addReplyForm" class="group-form" method="post"><input type="hidden" name="ua" id="UA_InputId" value="208tRPCEzMTQwMTgwMTUwOTE9U=|tSPCtSI0hif21lYiwhMzwiJ1luZG9nc3ItXV|tTPCtdKDwtKDwhOTAzPCQ0NzM8ITkyMDwhMDgwPCE5MjA8ITA0MD1dU=|tYPCIiLV|tZPCIiLV|tRMDwiIi1Q==|tRMjwiITMxNDAxODAyOTQwNzs4YWBweXdpYnxlJTZjdHItU=|tVPCtSIiwrVzY1PCM2NDY9XCI8IiIsJDMzMD1dU=|tVPCtSIiwrVzM2PCM1OTg9XCA8IiIsJDUxNT1dU=|tVPCtSIiwrVzQxPCM1NDA9XCA8IiIsJDc2OT1dU=|tVPCtSIiwrVzk2PCM2Nzk9XCI8IiIsJTE3MT1dU=|tVPCtSIiwrVzgyPCM2NDQ9XCA8IiIsJTM4OD1dU=|tVPCtSIiwrVzk5PCM2Nzg9XCA8IiIsJjM3MT1dU=|tVPCtSIiwrVzYwPCM1OTQ9XCI8IiIsJjgxMD1dU=|tVPCtSIiwrVzIzPCM1ODc9XCA8IiIsJjk4OD1dU=|tVPCtSIiwrVzMxPCM1ODk9XCA8IiIsJzE1NT1dU=|tVPCtSIiwrVzE0PCM2MTk9XCI8IiIsJzg1OD1dU=|tVPCtSIiwrVzAxPCM1OTU9XCA8IiIsKDA2MD1dU=|tVPCtSIiwrVzk0PCM2OTg9XCA8IiIsITE3OTQ9XV|tVPCtSIiwrVzk5PCM2NjY9XCI8IiIsITIwMzU9XV|tVPCtSIiwrWDA1PCM2MTg9XCA8IiIsITIyMzY9XV|tVPCtSIiwrWDc2PCMzOTM9XCA8IiIsITM3NTQ9XV|tVPCtSIiwrWDg4PCM2MTE9XCI8IiIsITQxMzg9XV|tVPCtSIiwrWDkwPCM1ODU9XCA8IiIsITQyOTE9XV|tVPCtSIiwrUTI0NDwjNjEzPVwgPCIiLCE1Mjk4PV1Q==|tVPC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XCI8IiIsIjg4MDI9XV|tVPCtSIiwrWDkwPCMyODI9XCA8IiIsIjg5ODg9XV|tVPCtSIiwrWTA2PCMxNTM9XCA8IiIsIjkzMDY9XV|tVPCtSIiwrWTI1PCMzMzU9XCI8IiIsIjk2NzQ9XV|tVPCtSIiwrWTI2PCMzMTM9XCA8IiIsIjk4MzU9XV|tVPCtSIiwrWTgxPCMxNjI9XCA8IiIsIzA0NDI9XV|tVPCtSIiwrWTg3PCMzNjE9XCI8IiIsIzA5MjI9XV|tVPCtSIiwrWTg1PCMzNDA9XCA8IiIsIzExMDA9XV|tVPCtSIiwrWTk0PCMxNjU9XCA8IiIsIzE2NzU9XV|tVPCtSIiwrUTAzNTwjMzUyPVwiPCIiLCMyMTMxPV1Q==|tWPCtSIiwhODwgPCEwMDIzMz1dU=|tWPCtSIiwhNzwiPCEwMDMyMj1dU=|tWPCtSIiwhODwgPCE2NDYyOD1dU=|tWPCtSIiwhNzwiPCE2NDY0OD1dU=">
 <input type="hidden" name="action" value="/forum/reply_action">
 <input type="hidden" name="_fmw.publis._0.g" value="154528">
 <input type="hidden" name="_fmw.publis._0.t" value="253626589">
 <input type="hidden" name="_fmw.publis._0.u" value="F193EF5FAC1808426985F70EA5152207">
 <input type="hidden" name="event_submit_do_publish" value="anything">
<input type="hidden" id="request_path" name="requestPath" value="/catalog/thread/154528-253626589-13.htm">
   <input type="hidden" id="tbToken" name="_fmw.publis._0.tb" value="3d803bd073eed">
 <fieldset>
 <div class="ke-editor-wrap" style="width: 99%; "> <div class="ke-editor-tools" onmousedown="return false;"><a class="ke-triplebutton-off ke-triplebutton" hidefocus="true" tabindex="0" title="预览" style="-webkit-user-select: none; "><span class="ke-toolbar-item ke-toolbar-preview"></span></a><span class="ke-toolbar-separator">&nbsp;</span><a class="ke-triplebutton ke-triplebutton-disabled" hidefocus="true" tabindex="0" title="撤销" style="-webkit-user-select: none; "><span class="ke-toolbar-item ke-toolbar-undo"></span></a><a class="ke-triplebutton ke-triplebutton-disabled" hidefocus="true" tabindex="0" title="重做" style="-webkit-user-select: none; "><span class="ke-toolbar-item ke-toolbar-redo"></span></a><span class="ke-toolbar-separator">&nbsp;</span><a class="ke-triplebutton-off ke-triplebutton" hidefocus="true" tabindex="0" title="清除格式" style="-webkit-user-select: none; "><span class="ke-toolbar-item ke-toolbar-removeformat"></span></a><span class="ke-select-wrap" style="-webkit-user-select: none; " title="大小"><a onclick="return false;" class="ke-select"><span class="ke-select-text" style="width: 30px; "><span class="ke-select-text-inner">大小</span></span><span class="ke-select-drop-wrap"><span class="ke-select-drop"></span></span></a></span><span class="ke-select-wrap" style="-webkit-user-select: none; " title="字体"><a onclick="return false;" class="ke-select"><span class="ke-select-text" style="width: 110px; "><span class="ke-select-text-inner">字体</span></span><span class="ke-select-drop-wrap"><span class="ke-select-drop"></span></span></a></span><a class="ke-triplebutton-off ke-triplebutton" hidefocus="true" tabindex="0" title="粗体 " style="-webkit-user-select: none; "><span class="ke-toolbar-item ke-toolbar-bold"></span></a><a class="ke-triplebutton-off ke-triplebutton" hidefocus="true" tabindex="0" title="斜体 " style="-webkit-user-select: none; "><span class="ke-toolbar-item ke-toolbar-italic"></span></a><a class="ke-triplebutton-off ke-triplebutton" hidefocus="true" tabindex="0" title="下划线 " style="-webkit-user-select: none; "><span class="ke-toolbar-item ke-toolbar-underline"></span></a><a class="ke-triplebutton-off ke-triplebutton" hidefocus="true" tabindex="0" title="删除线 " style="-webkit-user-select: none; "><span class="ke-toolbar-item ke-toolbar-strikeThrough"></span></a><a class="ke-triplebutton ke-triplebutton-off" hidefocus="true" tabindex="0" title="文本颜色" style="-webkit-user-select: none; "><span class="ke-toolbar-item ke-toolbar-color"></span></a><span class="ke-toolbar-separator">&nbsp;</span><a class="ke-triplebutton ke-triplebutton-off" hidefocus="true" tabindex="0" title="项目列表" style="-webkit-user-select: none; "><span class="ke-toolbar-item ke-toolbar-ul"></span></a><a class="ke-triplebutton ke-triplebutton-off" hidefocus="true" tabindex="0" title="编号列表" style="-webkit-user-select: none; "><span class="ke-toolbar-item ke-toolbar-ol"></span></a><a class="ke-triplebutton ke-triplebutton-disabled" hidefocus="true" tabindex="0" title="减少缩进量 " style="-webkit-user-select: none; "><span class="ke-toolbar-item ke-toolbar-outdent"></span></a><a class="ke-triplebutton ke-triplebutton-off" hidefocus="true" tabindex="0" title="增加缩进量 " style="-webkit-user-select: none; "><span class="ke-toolbar-item ke-toolbar-indent"></span></a><a class="ke-triplebutton ke-triplebutton-on" hidefocus="true" tabindex="0" title="左对齐" style="-webkit-user-select: none; "><span class="ke-toolbar-item ke-toolbar-alignleft"></span></a><a class="ke-triplebutton-off ke-triplebutton" hidefocus="true" tabindex="0" title="居中对齐" style="-webkit-user-select: none; "><span class="ke-toolbar-item ke-toolbar-aligncenter"></span></a><a class="ke-triplebutton-off ke-triplebutton" hidefocus="true" tabindex="0" title="右对齐" style="-webkit-user-select: none; "><span class="ke-toolbar-item ke-toolbar-alignright"></span></a><span class="ke-toolbar-separator">&nbsp;</span><a class="ke-triplebutton ke-triplebutton-off" hidefocus="true" tabindex="0" title="插入表情" style="-webkit-user-select: none; "><span class="ke-toolbar-item ke-toolbar-smiley"></span></a><span class="ke-toolbar-separator">&nbsp;</span><a class="ke-triplebutton ke-triplebutton-off" hidefocus="true" tabindex="0" title="插入表格" style="-webkit-user-select: none; "><span class="ke-toolbar-item ke-toolbar-table"></span></a><a class="ke-triplebutton ke-triplebutton-off" hidefocus="true" tabindex="0" title="全屏" style="-webkit-user-select: none; "><span class="ke-toolbar-item ke-toolbar-maximize"></span></a></div><div class="ke-textarea-wrap" style="height: 200px; "><iframe style="width:100%;height:100%;border:none;" width="100%" height="100%" frameborder="0" title="kissy-editor" src="" allowtransparency="true"></iframe><textarea id="msgpost" name="_fmw.publis._0.c" style="width: 100%; display: none; height: 100%; "></textarea></div><div class="ke-editor-status"><div class="ke-resizer" style="-webkit-user-select: none; "></div><div class="ke-draft"><spa class="ke-draft-title">内容正文每5分钟自动保存一次。</spa><span class="ke-draft-time"></span><a class="ke-button ke-draft-save-btn" style="vertical-align: middle; padding-top: 1px; padding-right: 9px; padding-bottom: 1px; padding-left: 9px; -webkit-user-select: none; "><span class="ke-draft-mansave"></span><span>立即保存</span></a><span class="ke-select-wrap" style="-webkit-user-select: none; " title="恢复编辑历史"><a onclick="return false;" class="ke-select"><span class="ke-select-text" style="width: 85px; "><span class="ke-select-text-inner">恢复编辑历史</span></span><span class="ke-select-drop-wrap"><span class="ke-select-drop"></span></span></a></span></div></div></div><div class="J_WS" style="font-size: 13px; padding-left: 5px; ">源码:已输入 <em class="J_WordSize" style="font-weight: bold; color: green; ">0</em>/最多输入 <em class="J_WsMax" style="font-weight: bold; ">20000</em> <span class="J_WsTips" style="color: red; "></span></div>
 <div style="float:right;margin-top:-20px">使用有问题?请看<a target="_blank" href="http://bbs.taobao.com/catalog/thread/1093005-250544615.htm">这里</a></div>
 <div class="Reply-info">
   <p class="verify">
   <button id="submitBtn" title="发表回复" class="btn-bm" name="button_publish" type="submit">发表回复</button>
 </p>
   </div>
 </fieldset>
 </form>



我想修改iframe中的html的body的内容 我的代码如下:
                HtmlElementCollection a = webBrowser1.Document.All["addReplyForm"].GetElementsByTagName("iframe");
                foreach (HtmlElement kk in a)
                {
                    textBox1.Text = kk.GetAttribute("src");
                }

获取到的却是整个网页的代码(是iframe上一层的整个网页的代码)。 我也不知道是我写错了还是这个网页做了什么手脚,弄不清楚了。希望各位大牛帮帮忙。
要是问题没说清楚。请各位大牛指正

5 个解决方案

#1


<iframe style="width:100%;height:100%;border:none;" width="100%" height="100%" frameborder="0" title="kissy-editor" src="" allowtransparency="true">
</iframe>

上面的html代码太长了 iframe被弄到外面去了 这里另外拿出来 看

#2


<html contenteditable="true"><head><title>${title}</title><link href="http://a.tbcdn.cn/s/kissy/1.1.6/editor/plugins/../theme/editor-iframe-min.css?t=2011-02-14%2014%3A32%3A25" rel="stylesheet"><style></style><style> table.ke_show_border, table.ke_show_border > tr > td,  table.ke_show_border > tr > th, table.ke_show_border > tbody > tr > td,  table.ke_show_border > tbody > tr > th, table.ke_show_border > thead > tr > td,  table.ke_show_border > thead > tr > th, table.ke_show_border > tfoot > tr > td,  table.ke_show_border > tfoot > tr > th{border : #d3d3d3 1px dotted}</style></head><body class="ke-editor" id="editorbodyid"><p><br></p></body></html>

#3


<html contenteditable="true"><head><title>${title}</title><link href="http://a.tbcdn.cn/s/kissy/1.1.6/editor/plugins/../theme/editor-iframe-min.css?t=2011-02-14%2014%3A32%3A25" rel="stylesheet"><style></style><style> table.ke_show_border, table.ke_show_border > tr > td,  table.ke_show_border > tr > th, table.ke_show_border > tbody > tr > td,  table.ke_show_border > tbody > tr > th, table.ke_show_border > thead > tr > td,  table.ke_show_border > thead > tr > th, table.ke_show_border > tfoot > tr > td,  table.ke_show_border > tfoot > tr > th{border : #d3d3d3 1px dotted}</style></head><body class="ke-editor" id="editorbodyid"><p><br></p></body></html>


这个是iframe中的内容 楼上贴的时候忘记说明了 没修改权限 ^^!!!

#4


http://jhxk.iteye.com/blog/458568
document.frames("frame_id").document.action;

#5


谢谢楼上 不过你那个是javascript的写法 我看了一下 C#里面的web控件 没这个属性啊 转换成C#
 怎么写呢

#1


<iframe style="width:100%;height:100%;border:none;" width="100%" height="100%" frameborder="0" title="kissy-editor" src="" allowtransparency="true">
</iframe>

上面的html代码太长了 iframe被弄到外面去了 这里另外拿出来 看

#2


<html contenteditable="true"><head><title>${title}</title><link href="http://a.tbcdn.cn/s/kissy/1.1.6/editor/plugins/../theme/editor-iframe-min.css?t=2011-02-14%2014%3A32%3A25" rel="stylesheet"><style></style><style> table.ke_show_border, table.ke_show_border > tr > td,  table.ke_show_border > tr > th, table.ke_show_border > tbody > tr > td,  table.ke_show_border > tbody > tr > th, table.ke_show_border > thead > tr > td,  table.ke_show_border > thead > tr > th, table.ke_show_border > tfoot > tr > td,  table.ke_show_border > tfoot > tr > th{border : #d3d3d3 1px dotted}</style></head><body class="ke-editor" id="editorbodyid"><p><br></p></body></html>

#3


<html contenteditable="true"><head><title>${title}</title><link href="http://a.tbcdn.cn/s/kissy/1.1.6/editor/plugins/../theme/editor-iframe-min.css?t=2011-02-14%2014%3A32%3A25" rel="stylesheet"><style></style><style> table.ke_show_border, table.ke_show_border > tr > td,  table.ke_show_border > tr > th, table.ke_show_border > tbody > tr > td,  table.ke_show_border > tbody > tr > th, table.ke_show_border > thead > tr > td,  table.ke_show_border > thead > tr > th, table.ke_show_border > tfoot > tr > td,  table.ke_show_border > tfoot > tr > th{border : #d3d3d3 1px dotted}</style></head><body class="ke-editor" id="editorbodyid"><p><br></p></body></html>


这个是iframe中的内容 楼上贴的时候忘记说明了 没修改权限 ^^!!!

#4


http://jhxk.iteye.com/blog/458568
document.frames("frame_id").document.action;

#5


谢谢楼上 不过你那个是javascript的写法 我看了一下 C#里面的web控件 没这个属性啊 转换成C#
 怎么写呢