解决 jQuery 实现父窗口的问题 如window.parent.document.getElementById().innerHTML

来源:互联网 发布:怎么看淘宝店主的电话 编辑:程序博客网 时间:2024/06/05 17:57

 

 

using System;
using System.Configuration;
using System.Data;
using System.Text;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Diagnostics;


public partial class RecPlay_RecPlay : System.Web.UI.Page
{
    public string RecName;
    public string PathTo_wav
    {
        get { return ViewState["pathTo_wav"].ToString(); }

        set { ViewState["pathTo_wav"] = value; }

    }
    public string PathTo_voc
    {
        get { return ViewState["pathTo_voc"].ToString(); }

        set { ViewState["pathTo_voc"] = value; }

    }
    public string ServiceID
    {
        get { return Request.QueryString["serviceid"].ToString(); }

    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.Page.IsPostBack)
        {
           // BuildWav(ServiceID);
        }

    }
  
    private void BuildWav(string serviceID)
    {
        if (!string.IsNullOrEmpty(serviceID))
        {
            if (this.Connect("10.6.27.8", "10086", ""))
            {
                string sql = "select REC_VOC_FILE from dc_servicelist where ServiceID='"+this.ServiceID+"'";

                if (gDAO.SqlText.ExecuteScalar(sql)!=null)
                {
                    if (gDAO.SqlText.ExecuteScalar(sql).ToString().IndexOf(".voc") != -1)
                    {
                        string path = @"//10.6.27.8/rec/rec/" + gDAO.SqlText.ExecuteScalar(sql).ToString();
                        ///Request.Cookies["UserInfo"]["userid"].ToString()
                        Do(path, "894");
                    }
                }
              
              

            }
       
        }
    }
    public void Do(string pathSource, string agentID)
    {
        string[] arr_path_target = pathSource.Split(new Char[] { '//' });//--0043957.voc
        string filename_voc = agentID + "_" + arr_path_target[arr_path_target.Length - 1].ToString();
        string filename_wav = filename_voc.Replace("voc", "wav");//--0043957.wav
        //string pathTo_voc = Server.MapPath(arr_path_target[arr_path_target.Length-1].ToString());
        string pathTo_voc = Server.MapPath("voc//" + filename_voc);
        string pathTo_wav = pathTo_voc.Replace("voc//" + filename_voc, "wav//" + filename_wav);

        this.PathTo_wav = pathTo_wav;//存储-用于关闭时候的删除wav文件动作;
        this.PathTo_voc = pathTo_voc;//存储-用于关闭时候的删除voc文件动作;

        if ((File.Exists(this.PathTo_voc)) && (File.Exists(this.PathTo_voc)))
        {
            this.RecName = this.PathTo_wav;
            return;
        }
        File.Copy(pathSource, pathTo_voc);
        int result=DjVocConvert.PcmtoWave(pathTo_voc, pathTo_wav);
        if (result > 0)
        {
            this.RecName = this.PathTo_wav; 
        }
    }
    /// <summary>
    /// Agent退出播放时候,只删除对应AgentID的录音wav
    /// </summary>
    public void Close()
    {
        //if (File.Exists(this.PathTo_wav))
        //{
        //    File.Delete(this.PathTo_wav);
        //}
        //if (File.Exists(this.PathTo_voc))
        //{
        //    File.Delete(this.PathTo_voc);
        //}
        // Response.Write("<script>top.document.getElementById('_DialogDiv_Diag2').hide();top.document.getElementById('_DialogBGDiv').hide();</script>");     //---Dialog.js
        string scripts = "<script>parent.$(/"#windownbg/").remove();parent.$(/"#windown-box/").fadeOut(/"slow/",function(){parent.$(this).remove();});</script>";//--tipswindown.js
        Response.Write(scripts); 
                                                          
    }
    protected void BtnClose_Click(object sender, EventArgs e)
    {
        Close();
    }
    /// <summary>
    /// 远程连接服务器;
    /// </summary>
    /// <param name="remoteHost"></param>
    /// <param name="userName"></param>
    /// <param name="passWord"></param>
    /// <returns></returns>
    public bool Connect(string remoteHost, string userName, string passWord)
    {
        bool Flag = true;
        Process proc = new Process();
        proc.StartInfo.FileName = "cmd.exe";
        proc.StartInfo.UseShellExecute = false;
        proc.StartInfo.RedirectStandardInput = true;
        proc.StartInfo.RedirectStandardOutput = true;
        proc.StartInfo.RedirectStandardError = true;
        proc.StartInfo.CreateNoWindow = true;
        try
        {
            proc.Start();
            string command = @"net  use  //" + remoteHost + "  " + passWord + "  " + "  /user:" + userName + ">NUL";
            proc.StandardInput.WriteLine(command);
            command = "exit";
            proc.StandardInput.WriteLine(command);
            while (proc.HasExited == false)
            {
                proc.WaitForExit(1000);
            }
            string errormsg = proc.StandardError.ReadToEnd();
            if (errormsg != "")
                Flag = false;
            proc.StandardError.Close();
        }
        catch (Exception ex)
        {
            Flag = false;
        }
        finally
        {
            proc.Close();
            proc.Dispose();
        }
        return Flag;
    }

}

 

-----------------------------------------------------------------------------/

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestJqueryMprPlugin2.aspx.cs" Inherits="RecPlay_TestJqueryMprPlugin2" %>

<!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>无标题页</title>
    <link rel="stylesheet" href="css/tipswindown.css" type="text/css" media="all" />
    <script type="text/javascript" src="tipswindown.js"></script>
    <script type="text/javascript" src="../public/javascript/jquery-1.3.js"></script>
     <script type="text/javascript">
 var $=jQuery;
 $(document).ready(function() {
 $("#text1").click(function() {
  tipsWindown("标题","text:提示信息内容","250","150","true","","true","text")
 });
 $("#text2").click(function() {
  tipsWindown("录音播放...","iframe:RecPlay.aspx","400","80","true","","false","text")
 });
 $("#text3").click(function() {
  tipsWindown("标题","text:我不能拖动,但3秒钟后我会自动消失","250","150","false","3000","true","text")
 });

 $("#id1").click(function() {
  tipsWindown("标题","id:testID","350","150","true","","true","id")
 });

 $("#img1").click(function() {
  tipsWindown("图片","img:http://leotheme.cn/wp-content/uploads/2008/09/tr2xcp6yw4o5xebj9s.jpg","500","230","true","","true","img")
 });

 $("#url1").click(function(){
  tipsWindown("标题","url:get?test.html","250","150","true","","true","text");
 });

 $("#iframe1").click(function(){
  tipsWindown("标题","iframe:http://leotheme.cn","950","527","true","","true","leotheme");
 });
 });
 </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="div888">
    <button id="text2">点击我弹出提示</button>
    </div>
    </form>
</body>
</html>
/-----------------------------------------

///-------------------------------------------------------------------------
//jQuery弹出窗口 By Await [2009-11-22]
//--------------------------------------------------------------------------
/*参数:[可选参数在调用时可写可不写,其他为必写]
----------------------------------------------------------------------------
    title: 窗口标题
  content:  内容(可选内容为){ text | id | img | url | iframe }
    width: 内容宽度
   height: 内容高度
  drag:  是否可以拖动(ture为是,false为否)
     time: 自动关闭等待的时间,为空是则不自动关闭
   showbg: [可选参数]设置是否显示遮罩层(0为不显示,1为显示)
  cssName:  [可选参数]附加class名称
 ------------------------------------------------------------------------*/
 //示例:
 //------------------------------------------------------------------------
 //simpleWindown("例子","text:例子","500","400","true","3000","0","exa")
 //------------------------------------------------------------------------
var showWindown = true;
var templateSrc = "http://leotheme.cn/wp-content/themes/Dreamy"; //设置loading.gif路径

function tipsWindown(title,content,width,height,drag,time,showbg,cssName) {
 $("#windown-box").remove(); //请除内容
 var width = width>= 950?this.width=950:this.width=width;     //设置最大窗口宽度
 var height = height>= 527?this.height=527:this.height=height;  //设置最大窗口高度
 if(showWindown == true) {
  var simpleWindown_html = new String;
   simpleWindown_html = "<div id=/"windownbg/" style=/"height:"+$(document).height()+"px;filter:alpha(opacity=0);opacity:0;z-index: 999901/"></div>";
   simpleWindown_html += "<div id=/"windown-box/">";
   simpleWindown_html += "<div id=/"windown-title/"><h2></h2><span id=/"windown-close/">关闭</span></div>";
   simpleWindown_html += "<div id=/"windown-content-border/"><div id=/"windown-content/"></div></div>";
   simpleWindown_html += "</div>";
   $("body").append(simpleWindown_html);
   show = false;
 }
 contentType = content.substring(0,content.indexOf(":"));
 content = content.substring(content.indexOf(":")+1,content.length);
 switch(contentType) {
  case "text":
  $("#windown-content").html(content);
  break;
  case "id":
  $("#windown-content").html($("#"+content+"").html());
  break;
  case "img":
  $("#windown-content").ajaxStart(function() {
   $(this).html("<img src='"+templateSrc+"' class='loading' />");
  });
  $.ajax({
   error:function(){
    $("#windown-content").html("<p class='windown-error'>加载数据出错...</p>");
   },
   success:function(html){
    $("#windown-content").html("<img src="+content+" alt='' />");
   }
  });
  break;
  case "url":
  var content_array=content.split("?");
  $("#windown-content").ajaxStart(function(){
   $(this).html("<img src='"+templateSrc+"' class='loading' />");
  });
  $.ajax({
   type:content_array[0],
   url:content_array[1],
   data:content_array[2],
   error:function(){
    $("#windown-content").html("<p class='windown-error'>加载数据出错...</p>");
   },
   success:function(html){
    $("#windown-content").html(html);
   }
  });
  break;
  case "iframe":
  $("#windown-content").ajaxStart(function(){
   $(this).html("<img src='"+templateSrc+"' class='loading' />");
  });
  $.ajax({
   error:function(){
    $("#windown-content").html("<p class='windown-error'>加载数据出错...</p>");
   },
   success:function(html){
    $("#windown-content").html("<iframe src=/""+content+"/" width=/"100%/" height=/""+parseInt(height)+"px"+"/" scrolling=/"auto/" frameborder=/"0/" marginheight=/"0/" marginwidth=/"0/"></iframe>");
   }
  });
 }
 $("#windown-title h2").html(title);
 if(showbg == "true") {$("#windownbg").show();}else {$("#windownbg").remove();};
 $("#windownbg").animate({opacity:"0.5"},"normal");//设置透明度
 $("#windown-box").show();
 if( height >= 527 ) {
  $("#windown-title").css({width:(parseInt(width)+22)+"px"});
  $("#windown-content").css({width:(parseInt(width)+17)+"px",height:height+"px"});
 }else {
  $("#windown-title").css({width:(parseInt(width)+10)+"px"});
  $("#windown-content").css({width:width+"px",height:height+"px"});
 }
 var cw = document.documentElement.clientWidth,ch = document.documentElement.clientHeight,est = document.documentElement.scrollTop;
 var _version = $.browser.version;
 if ( _version == 6.0 ) {
  $("#windown-box").css({left:"50%",top:(parseInt((ch)/2)+est)+"px",marginTop: -((parseInt(height)+53)/2)+"px",marginLeft:-((parseInt(width)+32)/2)+"px",zIndex: "999999"});
 }else {
  $("#windown-box").css({left:"50%",top:"50%",marginTop:-((parseInt(height)+53)/2)+"px",marginLeft:-((parseInt(width)+32)/2)+"px",zIndex: "999999"});
 };
 var Drag_ID = document.getElementById("windown-box"),DragHead = document.getElementById("windown-title");
  
 var moveX = 0,moveY = 0,moveTop,moveLeft = 0,moveable = false;
  if ( _version == 6.0 ) {
   moveTop = est;
  }else {
   moveTop = 0;
  }
 var sw = Drag_ID.scrollWidth,sh = Drag_ID.scrollHeight;
  DragHead.onmouseover = function(e) {
   if(drag == "true"){DragHead.style.cursor = "move";}else{DragHead.style.cursor = "default";}
  };
  DragHead.onmousedown = function(e) {
  if(drag == "true"){moveable = true;}else{moveable = false;}
  e = window.event?window.event:e;
  var ol = Drag_ID.offsetLeft, ot = Drag_ID.offsetTop-moveTop;
  moveX = e.clientX-ol;
  moveY = e.clientY-ot;
  document.onmousemove = function(e) {
    if (moveable) {
    e = window.event?window.event:e;
    var x = e.clientX - moveX;
    var y = e.clientY - moveY;
     if ( x > 0 &&( x + sw < cw) && y > 0 && (y + sh < ch) ) {
      Drag_ID.style.left = x + "px";
      Drag_ID.style.top = parseInt(y+moveTop) + "px";
      Drag_ID.style.margin = "auto";
      }
     }
    }
  document.onmouseup = function () {moveable = false;};
  Drag_ID.onselectstart = function(e){return false;}
 }
 $("#windown-content").attr("class","windown-"+cssName);
 var closeWindown = function() {
     $("#windownbg").remove();
  $("#windown-box").fadeOut("slow",function(){$(this).remove();});
 }
 if( time == "" || typeof(time) == "undefined") {
  $("#windown-close").click(function() {
     
      return;//Eman 封锁了此关闭事件。
   $("#windownbg").remove();
   $("#windown-box").fadeOut("slow",function(){$(this).remove();});
  });
 }else {
  setTimeout(closeWindown,time);
 }
}
-----------------------tipswindown.js---///////////////////////

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

因为先前遇到的问题,所以我考虑采用 IFRAME 来隔离不同的脚本,从而实现我需要的效果。

在框架中,我用 JavaScript 获取 JSON 数据,组织成 HTML 代码,最后将其填充至上层文档的一个元素中。按照一般的写法,我们需要用到类似如下的语句:

1.window.parent.document.getElementById("myEle").innerHTML = html;

使用 jQuery ,写法如下:

1.$("#myEle", window.parent.document).html(html);

即指明了是在 window.parent.document 中查找 id=myEle 的元素。

随着前面的问题的解决(其实是对 jQuery 的了解不够),现在两种方案都可以实现我需要的效果了。

另外还有一种实现方式,代码如下:

1.parent.$("#myEle").html(html);

这种方法要求父文档也要调用 jQuery 。

演示:使用 jQuery 实现 window.parent.document.getElementById().innerHTML

 

个人感觉 jquery 就是强啦!!!

 

 

原创粉丝点击