抱歉,这个简单的问题。 我不确定这一切是否重要,但我会提及以防万一。 :当用户点击链接时,会发生以下情况:
function begin(some info) is called->Makes an Ajax request to backend PHP->
PHP calls the callback function->Callback function calls another JS function that creates a popup->
In the popup creating function, The Save button is assigned a function that makes an ajax request and sends PHP some user input.->
PHP makes a callback to another function that does nothing.
这里,这是将弹出框组合在一起的功能。
function collection(name, description, data){
var json = data;
var cont = openSitePopup("400","300");
//We create div objects.
var namecell = ce("div","sitePopupCell");
//Stuff
// We create a button and assign the createProducts Method to it.
var sbtbutton = createBtn("submitObject","SAVE","createProducts()");
//We append all the div objects to the popup.
cont.appendChild(namecell);
//..
}
function openSitePopup(width,height) {
//try to center the popup if values are not passed
var xPos = (getWinWidth()/2) - (width/2) + sl;
var yPos = (getWinHeight()/2) - (height/2) + st;
sitepopupwin = ge("sitePopupWin");
clearElement(sitepopupwin);
var winhandle = ce("div","","sitePopupHandle");
sitepopupwin.style.display = "block";
//Other style assignments.
//closebutton
var close = ce("img","sitePopupCloseBtn");
close.setAttribute("src",theme_path + "/images/icons/close.png");
//start adding goodies
var mydiv = ce("div","sitePopupContainer");
winhandle.appendChild(close);
winhandle.appendChild(createCleaner());
sitepopupwin.appendChild(winhandle);
sitepopupwin.appendChild(mydiv);
//return reference to the container for adding stuff
return mydiv;
}
function createProducts()
{
//Some exciting Ajax stuff with a callback to writeNewFolder()
}
function writeNewFolder(data){
//Nothing of interest here...yet.
}
现在,当我按下弹出窗口上的Save
按钮时,请求成功,但弹出窗口没有关闭。我知道Window.Close()
函数,但它不起作用。 cont.Close()
似乎是一个明显的选择,但在这种情况下,我收到此错误:Uncaught TypeError: Object #<HTMLDivElement> has no method 'Close'
因此,Cont只是一个div元素。 openSitePopup()
方法仅返回div。
感谢您的帮助。
编辑:
function ce(elementType,elementClass,elementId,txt) {
var e = document.createElement(elementType);
//add optional parameters
if (elementId) e.setAttribute("id",elementId);
if (elementClass) setClass(e,elementClass);
//append extra text. If passed an object, append with without the textnode wrapper
if (isData(txt)) {
if (typeof(txt)=="object") e.appendChild(txt);
else e.appendChild(ctnode(txt));
}
return e;
}
希望原始创作者不介意我在这里发布他的一些代码。嗯,它是免费和开源的,所以它应该没问题......我想。
编辑2:ge
功能。这个很简单。
function ge(element) {
return document.getElementById(element);
}
答案 0 :(得分:1)
您没有发布创建不是window
弹出窗口的函数ge和ce,因此您无法.close()
试
ge('sitePopupWin').style.display='none';
或
var popup = ge('sitePopupWin');
popup.parentNode.removeChild(popup);