Javascript 我能';我不知道如何关闭一个简单的弹出窗口
对不起,这个问题太简单了。 我不确定这一切是否重要,但我会提到它以防万一当用户单击链接时,会发生以下情况:Javascript 我能';我不知道如何关闭一个简单的弹出窗口,javascript,popup,Javascript,Popup,对不起,这个问题太简单了。 我不确定这一切是否重要,但我会提到它以防万一当用户单击链接时,会发生以下情况: 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 p
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()
似乎是一个明显的选择,但在这种情况下,我得到了以下错误:uncaughttypeerror:Object#没有方法“Close”
因此,cont只是一个div元素。openSitePopup()
方法只返回一个div
谢谢你的帮助
编辑:
希望最初的创建者不介意我在这里发布他的一些代码。嗯,它是免费的,开源的,所以应该没问题……我想
编辑2:ge
功能。这个很简单
function ge(element) {
return document.getElementById(element);
}
您没有发布创建弹出窗口的函数ge和ce,该弹出窗口不是
窗口
,因此您无法.close()
试一试
ge('sitePopupWin').style.display='none'代码>
或
您没有发布创建弹出窗口的函数ge和ce,该弹出窗口不是窗口
,因此您无法.close()
试一试
ge('sitePopupWin').style.display='none'代码>
或
我道歉!我认为ce
是一个标准的JavaScript函数。它基本上创建了一个元素。我会加进去的。你的解决方案奏效了,非常感谢。你是对的,这不是一个窗口元素,只是一个div。多么有趣。我道歉!我认为ce
是一个标准的JavaScript函数。它基本上创建了一个元素。我会加进去的。你的解决方案奏效了,非常感谢。你是对的,它不是一个窗口元素,只是一个div。多么有趣。
function ge(element) {
return document.getElementById(element);
}
var popup = ge('sitePopupWin');
popup.parentNode.removeChild(popup);