导航

iframe动态改变src的测试

Posted on 2008-04-17 17:15  菜鸟都不容易  阅读(450)  评论(0编辑  收藏  举报
 <iframe name="frame1" id="frame1" src="" width="400" height="400"></iframe><br />
<input name="btn2" type="button" id="btn2" value="按钮一(不行)" onclick="document.frames['frame1'].src='http://www.163.com/';" />
<input name="btn3" type="button" id="btn3" value="按钮二(不行)" onclick="document.frames['frame1'].document.location.href='http://www.sohu.com/';" />
<input name="btn" type="button" id="btn" value="按钮三(可以)" onclick="document.getElementById('frame1').src='http://www.hao123.com/';" />


<input name="btn4" type="button" id="btn4" value="按钮四(可以)" onclick="window.open('http://www.mzwu.com/','frame1');" />
<a href="http://www.webjx.com/" target="frame1">网页教学网(可以)</a>
本文来自:网页教学网(www.webjx.com)原文链接:http://www.webjx.com/html_xhtml/20071210/html_xhtml_1923.html
 
先在aspx文件里放下iframe:  
  <iframe   runat=server   id=ifrm></iframe>  
  然后在cs文件里加定义:  
  protected   System.Web.UI.HtmlControls.HtmlControl   ifrm;  
   
  最后在你需要加iframe的src的地方写:  
  ifrm.Attributes.Add("src","地址");