透過後台去呼叫javascript的方法
這邊把常常用到的關閉瀏覽器當作範例
IE Firefox Chome 測試過都OK
廢話不多說..............
頁前
1: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="closeIE.aspx.cs" Inherits="Default3" %>
2:
3: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4:
5: <html xmlns="http://www.w3.org/1999/xhtml">
6: <head runat="server">
7: <script language="javascript">1:
2:
3: var browserName = navigator.appName;4: if (browserName == "Netscape") {5: function closeme() {6: window.open('', '_self', '');7: window.close();
8: }
9: }
10: else {11: if (browserName == "Microsoft Internet Explorer") {12: function closynoshowsme() {13: window.opener = "whocares";14: window.close();
15: }
16: }
17: }
18:
</script>
8: <title></title>
9: </head>
10: <body>
11: <form id="form1" runat="server">
12: <div>
13:
14: <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
15:
16: </div>
17: </form>
18: </body>
19: </html>
頁後
1: using System;
2: using System.Collections.Generic;
3: using System.Linq;
4: using System.Web;
5: using System.Web.UI;
6: using System.Web.UI.WebControls;
7:
8: public partial class Default3 : System.Web.UI.Page
9: {
10: protected void Page_Load(object sender, EventArgs e)
11: {
12:
13: }
14: protected void Button1_Click(object sender, EventArgs e)
15: {
16: Page.RegisterStartupScript("Show", "<script language=\"JavaScript\">closeme();</script>");
17: }
18: }
筆記紀錄中
大家一起加入blogads 賺零用錢!!