跨框架的遮罩层(jquery)

来源:互联网 发布:ug哪个版本编程最好用 编辑:程序博客网 时间:2024/05/23 19:15
function CreatNode(w, h, s) {    //参数w为弹出页面的宽度,参数h为弹出页面的高度,参数s为弹出页面的路径    var NewMask = window.parent.document.createElement_x("div");    NewMask.id = "Mask";    NewMask.style.position = "absolute";    NewMask.style.top = "0";    NewMask.style.left = "0";    NewMask.style.zIndex = "9";    NewMask.style.backgroundColor = "#000";    NewMask.style.filter = "alpha(opacity=70)";    NewMask.style.opacity = "0.7";    NewMask.style.width = "100%";    NewMask.style.height = (window.parent.document.body.scrollHeight + 50) + "px";    var NewDiv = window.parent.document.createElement_x("div");    NewDiv.id = "newdiv";    NewDiv.style.width = w;    NewDiv.style.height = h;    NewDiv.style.position = "absolute";    NewDiv.style.top = (window.screen.height - 450) / 4 + "px"    NewDiv.style.left = (window.screen.width - 910) / 2 + "px";    NewDiv.style.zIndex = "99"; ;    var NewFrame = window.parent.document.createElement_x("iframe");    NewFrame.id = "frame"    NewFrame.setAttribute("frameBorder", "0");    NewFrame.setAttribute("scrolling", "no");    NewFrame.setAttribute("allowTransparency", "true");    NewFrame.setAttribute("width", w);    NewFrame.setAttribute("height", h);    NewFrame.setAttribute("src", s);    var NewImg = window.parent.document.createElement_x("img");    NewImg.id = "newimg"    NewImg.style.cursor = "pointer";    NewImg.style.position = "relative";    NewImg.style.top = "-479px";    NewImg.style.left = "880px";    NewImg.onclick = function() {        Cancel();    }    NewImg.setAttribute("src", "images/del.png")    NewImg.setAttribute("title", "点击关闭")    $("body", window.parent.document).append(NewMask); //这里用了jquery的添加节点方式,如果没有jquery文件可改成window.parent.document.body.appendChild(NewMask);    $("body", window.parent.document).append(NewDiv);    $("#newdiv", window.parent.document).append(NewFrame);    $("#newdiv", window.parent.document).append(NewImg);}//移除添加的节点function Cancel() {    window.parent.document.body.removeChild(window.parent.document.getElementByIdx_x("Mask"));    window.parent.document.body.removeChild(window.parent.document.getElementByIdx_x("newdiv"));}

以下代码收集于网络,大家做的时候可以自己修改!