笔记:操作多个iframe
功能要求:在调用了多个iframe的页面使用按钮操纵iframe中的方法
暂时使用了两种方法,感觉不是很好:
1.使用cookie
在外面页面做一个cookie,在iframe中检查一下,发现清除有问题
(1)只保存一个空cookie
1 protected void btnLoad_Click(object sender, EventArgs e)
2 {
3 String cookieName = "loadCookie";
4 HttpCookie cookie = new HttpCookie(cookieName);
5 DateTime dt = DateTime.Now;
6 TimeSpan ts = new TimeSpan(0, 0, 10, 0);//10分钟
7 cookie.Expires = dt.Add(ts);
8 Response.Cookies.Add(cookie);
9 }
2 {
3 String cookieName = "loadCookie";
4 HttpCookie cookie = new HttpCookie(cookieName);
5 DateTime dt = DateTime.Now;
6 TimeSpan ts = new TimeSpan(0, 0, 10, 0);//10分钟
7 cookie.Expires = dt.Add(ts);
8 Response.Cookies.Add(cookie);
9 }
在iframe中使用并将时间减少:
1 if (Request.Cookies["loadCookie"] != null)
2 {
3 HttpCookie cookie = Request.Cookies["loadCookie"];
5 cookie.Expires = DateTime.Now.AddMinutes(-10);
6}
2 {
3 HttpCookie cookie = Request.Cookies["loadCookie"];
5 cookie.Expires = DateTime.Now.AddMinutes(-10);
6}
(2)在cookie里面加个值
1 protected void btnLoad_Click(object sender, EventArgs e)
2 {
3 String cookieName = "loadCookie";
4 HttpCookie cookie = new HttpCookie(cookieName);
5 DateTime dt = DateTime.Now;
6 TimeSpan ts = new TimeSpan(0, 0, 10, 0);//10分钟
7 cookie.Values.Add("Flag", "Flag");
8 cookie.Expires = dt.Add(ts);
9 Response.Cookies.Add(cookie);
10 }
11
2 {
3 String cookieName = "loadCookie";
4 HttpCookie cookie = new HttpCookie(cookieName);
5 DateTime dt = DateTime.Now;
6 TimeSpan ts = new TimeSpan(0, 0, 10, 0);//10分钟
7 cookie.Values.Add("Flag", "Flag");
8 cookie.Expires = dt.Add(ts);
9 Response.Cookies.Add(cookie);
10 }
11
在iframe中使用并清除:
1 if (Request.Cookies["loadCookie"] != null)
2 {
3 if (Request.Cookies["loadCookie"].Values["Flag"] == "Flag")
4 {
6 Request.Cookies["loadCookie"].Values.Clear();
7 }
8 }
2 {
3 if (Request.Cookies["loadCookie"].Values["Flag"] == "Flag")
4 {
6 Request.Cookies["loadCookie"].Values.Clear();
7 }
8 }
2.使用session
单击事件加个session:
1Session["Load"] = "Load";
iframe中使用:
1 if (Session["Load"] != null)
2 {
4 count++;
5 if (count == countNum)
6 {
7 Session["Load"] = null;
8 count = 0;
9 }
10 }
2 {
4 count++;
5 if (count == countNum)
6 {
7 Session["Load"] = null;
8 count = 0;
9 }
10 }
不知道哪里有问题,只是凭空想出来的,以后用的时候再想想
哪位要是能帮指正一下更好
终于找到了好方法:用js条用iframe中button的click
1 function loadBatch()
2 {
3 var num=document.all["txtHiddenNum"].value;
4 for(i=1;i<=num;i++)
5 {
6 var buttonObject = eval("subPrintIframe"+i+".document.all['loadButton']")
7 buttonObject.click();
8 }
9 return false;
10 }
2 {
3 var num=document.all["txtHiddenNum"].value;
4 for(i=1;i<=num;i++)
5 {
6 var buttonObject = eval("subPrintIframe"+i+".document.all['loadButton']")
7 buttonObject.click();
8 }
9 return false;
10 }
其中iframe的id为:id='subPrintIframe"+i+"'
js就是好啊
HelloWorld