锁定老帖子 主题:iframe中的子窗体调用父窗体中的方法
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-11-11
最后修改:2008-11-12
iFrame语法: iframe
标签 -- 代表HTML内联框架
示例<iframe src="http://www.dreamdu.com/xhtml/" width="200" height="500"></iframe>
主窗体:<html> <HEAD> <TITLE> CSI System </TITLE> </HEAD> <SCRIPT LANGUAGE="JavaScript"> <!-- function f1(str) { alert("Hello, " + str + ", 我是 CSI System 的JavaScript Method!"); } //--> </SCRIPT> <body> <Iframe src="cti.html" width="250" height="200" scrolling="no" frameborder="1"> </iframe> <h1 id="myH2">hello,I'm CSI!</h1> </body> </html> 子窗体:<HTML> <HEAD> <TITLE> CTI System</TITLE> </HEAD> <SCRIPT LANGUAGE="JavaScript"> <!-- function f2(s) { window.parent.f1(s); } //--> </SCRIPT> <BODY> <FORM METHOD=POST ACTION=""> <INPUT type="button" value="Click Me!" onclick="f2('CTI');"> </FORM> I am in CTI System! </BODY> </HTML> 效果:
参考: 4、JavaScript改变iframe的属性(地址,高度,宽度) 8、DHTML参考手册:IFRAME 元素 | iframe 对象 10、IFrame语法小全
参考网页:http://www.cnblogs.com/waxdoll/articles/271018.html
5.2.6 JavaScriptMany web pages use JavaScript to perform complex interactions between the user and the page. It is important to know how to execute JavaScript functions from within Internet explorer. The simplest method is to use Navigate with the prefix javascript: then the function name. However, this does not give us a return value, nor will it work correctly in all situations. We shall start with a HTML page, which contains a JavaScript function to display some text. This will be saved as JavaScript.html <html> <span id="hiddenText" style="display:none">This was displayed by javascript</span> <script language="javascript"> function jsFunction() { window.document.all["hiddenText"].style.display="block"; return "ok"; } </script> </html>
We can then use the Document.InvokeScript method to execute the JavaScript thus: C# 2.0 private void btnNavigate_Click(object sender, System.EventArgs e) { NavigateToUrlSync(@"C:\javascript.html"); string strRetVal = ""; strRetVal = (string)WebBrowser.Document.InvokeScript("jsFunction"); MessageBox.Show(strRetVal); }
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
浏览 8460 次