`
sqj47sqj
  • 浏览: 30746 次
社区版块
存档分类
最新评论

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

 
阅读更多

  function tipsWindown(title,content,width,height,drag,time,s howbg,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 = "";
  simpleWindown_html += "";
  simpleWindown_html += "关闭";
  simpleWindown_html += ""; 
  simpleWindown_html += "";
  $("body").append(simpleWindown_html);
  show = false;
  }
  contentType = content.substring(0,content.indexOf(":"));
  content = content.substring(content.indexOf(":")+1,content.l ength);
  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("");
  });
  $.ajax({
  error:function(){
  $("#windown-content").html("加载数据出错...");
  },
  success:function(html){
  $("#windown-content").html("");
  }
  });
  break;
  case "url":
  var content_array=content.split("?");
  $("#windown-content").ajaxStart(function(){
  $(this).html("");
  });
  $.ajax({
  type:content_array[0],
  url:content_array[1],
  data:content_array[2],
  error:function(){
  $("#windown-content").html("加载数据出错...");
  },
  success:function(html){
  $("#windown-content").html(html);
  }
  });
  break;
  case "iframe":
  $("#windown-content").ajaxStart(function(){
  $(this).html("");
  });
  $.ajax({
  error:function(){
  $("#windown-content").html("加载数据出错...");
  },
  success:function(html){
  $("#windown-content").html("");
  }
  });
  }
  $("#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((c h)/2)+est)+"px",marginTop: -((parseInt(height)+53)/2)+"px",marginLeft:-((pars eInt(width)+32)/2)+"px",zIndex: "999999"});
  }else {
  $("#windown-box").css({left:"50%",top:"50%",margin Top:-((parseInt(height)+53)/2)+"px",marginLeft:-((p arseInt(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  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-"+cssN ame);
  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 代码,最后将其填充至上层文档的一个元素中。按照一般的写法,我们需要用到类似如下的语句: 使用 jQuery ,写法如下: 即指明了是在 window.parent.document 中查找 id=myEle 的元素。
  随着前面的问题的解决(其实是对 jQuery 的了解不够),现在两种方案都可以实现我需要的效果了。
  另外还有一种实现方式,代码如下: 这种方法要求父文档也要调用 jQuery 。
  演示:使用 jQuery 实现 window.parent.document.getElementById().innerHTML
  个人感觉 jquery 就是强啦!!!
分享到:
评论

相关推荐

    jQuery子窗体取得父窗体元素的方法

    window.parent.document.getElementById(父窗口元素ID); 取父窗口的元素方法: $(selector, window.parent.document); 取父窗口的父窗口的元素就可以用: $(selector, window.parent.parent.document); 类似的,取...

    浅谈js中子页面父页面方法 变量相互调用

    (1)子页面调用父页面的方法或者变量: window.parent.方法()或者变量名 window.parent相当于定位到...window.parent.getElementById("aaa").value; //js的写法 (2)父页面调取子页面 主要是通过contentWindow定位到

    window.parent调用父框架时 ie跟火狐不兼容问题

    } [removed] 修改代码:(在ie和火狐当中均正常) 代码如下: [removed] function oa_tool1(){ window.parent.document.getElementById(“mm”).rows=”20,200,10,*”; } [removed] 原因: 从原则上来讲,修改后的...

    js与jQuery 获取父窗、子窗的iframe

    在web开发中,经常会用到iframe,难免会碰到需要在父窗口中使用iframe中的元素、或者在iframe框架中使用父窗口的元素 js 在父窗口中获取iframe中的元素 1、 格式:window.frames[“iframe的name值”].document....

    javascript window.opener的用法分析

    比如点击了a.htm上的一个链接而打开了b.htm,然后我们打算在b.htm上输入一个值然后赋予a.htm上的一个id为“name”的textbox中,就可以写为: window.opener.document.getElementById(“name”).value = “输入的数据...

    document.getElementById()

    document.getElementById()对象和使用方法

    各浏览器对document.getElementById等方法的实现差异解析

    主要是对各浏览器对document.getElementById等方法的实现差异进行了详细的分析介绍,需要的朋友可以过来参考下,希望对大家有所帮助

    获取页面长宽和滚动条的位置

    var div = document.getElementById("div"); for(var i=0; i; i++) { document.body.appendChild(document.createTextNode("Hello, World!")); document.body.appendChild(document.createElement("br"));...

    jquery 子窗口操作父窗口的代码

    $(“#父窗口元素ID”,window.parent.document)…就行了 js 版本 view sourceprint?1.window.parent.document.getElementById()

    innerHTML的使用

    innerHTML的使用document.getElementById("id").innerHTML = "contenttext";

    jQuery快速开发资料jQuery案例 代码 素材 笔记 作业资料.zip

    jQuery快速开发资料jQuery案例 代码 素材 笔记 作业资料,学习资料 01-getElementById获取元素.html 02-getElementsByTagName获取某些元素.html 03-H5新增获取元素方式(1).html 04-获取特殊元素.html 05-事件三要素....

    iframe子父页面调用js函数示例

    子页面取父页面中的标签中的值,比如该标签的id为“test”,则: 代码如下: window.parent.document.getElementById(“test”).value; jQuery方法为: $(window.parent.document).contents().find(“test”).val(); ...

    浅谈vue中document.getElementById()拿到的是原值的问题

    主要介绍了浅谈vue中document.getElementById()拿到的是原值的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

    javascript函数的解释

    72.JS中指定当前打开窗口的父窗口:window.opener,支持opener.opener...的多重继续. 73.JS中的self指的是当前的窗口 74.JS中状态栏显示内容:window.status="内容" 75.JS中的top指的是框架集中最顶层的框架 76.JS中...

    firefox下frameset取不到值的解决方法

    ff里不能通过对Frame的ID来直接访问 (IE FF都可以直接通过Frame的Name来访问,但是FrameSet不支持name属性) 因此window.parent.full =》window.parent.document.getElementById(“full”); js操作frame详细解说,...

    jQueryAPI_CHM(1.3).CHM与语法总结

     如:$(document.getElementById("msg"))则为jquery对象,可以使用jquery的方法。 由于jquery对象本身是一个集合。所以如果jquery对象要转换为dom对象则必须取出其中的某一项,一般可通过索引取出。 如:$("#msg")...

    document.getElementById介绍

    } $(function(){ var g = document.getElementById , w = window.testFunc ; //g alert&#40;typeof(g&#41;); alert&#40;String(g&#41;); alert&#40;g instanceof Object&#41;; alert&#40;g instanceof Function&#41...

    【JavaScript源代码】vue使用echarts图表自适应的几种解决方案.docx

    使用window.onresize let myChart = echarts.init(document.getElementById(dom)) window.onresize = function () { myChat.resize() } 优点:可以根据窗口大小实现自适应 缺点: 多个图表自适应写法比较麻烦...

    子窗体与父窗体传值示例js代码

    代码如下: //返回值给父窗体 function returnParent(value) {//获取子窗体返回值 var parent = window.dialogArguments;... //关闭子页面 } //window.opener.document.getElementById(“ActivityPic”);

    一行代码告别document.getElementById

    当初那种直接访问id的方法,逐渐被document.getElementById所替代。如果这年头还在用id访问元素,要么就是做程序里的内嵌网页,要么就是像铁道部那样的超境界仿古网站:) 当然只要保证你的用户都是用ie访问,这样的...

Global site tag (gtag.js) - Google Analytics