使用Jquery向一个空白网页动态创建一个iframe 及嵌入页面 和向嵌入页面传参

using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Collections.Specialized;
using Microsoft.JScript;
namespace MCS
{
    public partial class MyDialog : System.Web.UI.Page
    {
        protected string strParam = null;
        private void Page_Load(System.Object sender, System.EventArgs e)
        {

        }

        public string GetParam()
        {
            strParam = string.Empty;
            int loop1 = 0;
            int loop2 = 0;
            string[] arr1 = null;
            string[] arr2 = null;
            NameValueCollection coll = null;

            //Load Form variables into NameValueCollection variable.
            coll = Request.QueryString;
            //Get Names of all keys into a string array.
            arr1 = coll.AllKeys;
            for (loop1 = 0; loop1 <= arr1.GetUpperBound(0); loop1++)
            {
                strParam = strParam + arr1[loop1] + "=";
                // Get all values under this key.
                arr2 = coll.GetValues(loop1);
                for (loop2 = 0; loop2 <= arr2.GetUpperBound(0); loop2++)
                {
                    if (Information.IsDate(arr2[loop2]))
                        arr2[loop2] = DateTime.Parse(arr2[loop2]).ToString("MM/dd/yyyy hh:mm:ss tt");

                    strParam = strParam + arr2[loop2] + "&";
                }
            }

            if (strParam.Length > 0 && strParam.Contains("&"))
                strParam = strParam.TrimEnd('&');
            return strParam;
        }

        public string GetPage()
        {
            return Request.QueryString["Page"];
        }
    }
}

以上GetPage方法得到iframe里嵌入的页面,GetParam方法则是得到要传递的参数

下面是前台Jquery页面

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MyDialog.aspx.cs" Inherits="MCS.MyDialog" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Dialog</title>
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script type="text/javascript" language="javascript">
        $(document).ready(function () {
            var if_w = $("body").width();
            var if_h = $(window).height();
            $("<iframe width='" + if_w + "' height='" + if_h + "' id='Frame1'></iframe>").prependTo('body');
            $("#Frame1").attr("src", "<%= GetPage() %>" + "?" + unescape("<%= GetParam() %>"));
        });
    </script>
</head>
<body>
</body>
</html>

至于为什么要放在iframe里面,而不直接使用load方法,是为了防止跳转时弹出一个新页面,而不是在本页面中跳转

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

猜你喜欢

转载自www.cnblogs.com/swdhywhd/p/10310664.html