• asp.net模态窗口返回值


      个人感觉模态窗口在做网站的时候,使用到的比较少,前段时间在做项目时要实现以模态窗口传值和接收返回值,

    模态窗口传值实现比较简单,但是做好后发现在Chrome浏览器中接收不到返回值,修改好Chrome浏览器的问题后

    大概过了有两个星期又发现在IE6下会报错,最终在网上搜索解决办法才修改好

    代码:

    A为父页面,B为子页面

    A页面代码:

     //打开选择客户的模态窗口
            function sc(tag) {
                var recdata = false;
                var strDialogFeatures = "status=no;center=yes;help=no;dialogWidth=700px;dialogHeight=600px;scroll=yes;resize=no";
                recdata = showModalDialog("Modal_List_forother.aspx?id=" + tag + "", "newwindow", strDialogFeatures);
           //此处的if判断语句必须需要,如果直接用recdata=window.returnValue赋值的话在IE6下会无法获取到返回值,至于原因,我也不清楚I'M SORRY o(╯□╰)o
    if (recdata == undefined) { recdata = window.returnValue; } if (recdata != undefined) { //刷新父窗口 此处可以不刷新 因项目功能需要 所以在此处做了刷新操作 var url = window.location.href.toString();
             //此处省略对变量url的部分操作,根据需要实现的功能不同代码也会不一样 window.location.href
    = url; } }

    B页面代码:

    首先在要想在IE6下也能接收模态窗口返回值 先要在B页面的head部分添加代码<base target="_self" />

    如下:

    <head runat="server">
        <title>子窗口</title>
        <link href="Styles/basic.css" rel="stylesheet" type="text/css" />
        <base target="_self" />
    </head>

    要想从后台返回值到父页面去,我们还需在页面的cs文件中添加如下代码:

               string strscripts = "";
               strscripts = strscripts + "<script type="text/javascript">";
           //这是原先的返回值代码,也是正确的,只是嫌太长不想用
    //strscripts = strscripts + " if(window.opener!=undefined){ window.opener.returnValue = '" + name + "'; }else{window.returnValue = '" + name //+ "';} window.close();</script>"; strscripts = strscripts + " window.returnValue = '" + name+ "';window.close();</script>"; ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script type="text/javascript"> window.returnValue = '" + name + "';window.close();</script>");
  • 相关阅读:
    git版本超前了N个版本且落后了N个版本的解决办法
    CSS3与动画有关的属性transition、animation、transform对比
    禁止选中文本JS
    页面加载中jquery逐渐消失效果实现
    localstorage和sessionstorage上手使用记录
    点击除元素以外的任意地方隐藏元素js
    js准确获取当前页面url网址信息
    301、404、200、304、500HTTP状态
    对事件委托绑定click的事件的解绑
    RabbitMQ的安装和使用Python连接RabbitMQ
  • 原文地址:https://www.cnblogs.com/xuxw/p/3416455.html
Copyright © 2020-2023  润新知