javascript 我如何在 php 中关闭弹出窗口...?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5733420/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how i can close popup window in php ...?
提问by saint
i have a page in where the different button available. on each button when a user click a popup window open. e.g user click on ADD button and a popup window appear. user put some data in controls and press on save button. i want to close the open popup when user press on save and and data save successfully. i m using this code to close the form
我有一个页面,其中有不同的按钮可用。当用户单击打开的弹出窗口时,在每个按钮上。例如,用户单击“添加”按钮并出现一个弹出窗口。用户将一些数据放入控件并按下保存按钮。当用户按下保存并成功保存数据时,我想关闭打开的弹出窗口。我使用此代码关闭表单
function closeForm() {
echo "<script language=\"JavaScript\">\n";
echo "function closeForm(){ \n";
echo "window.self.close();";
echo " } \n";
echo "</script>\n";
return true;
}
this function call if the data successfully save.
如果数据成功保存,则调用此函数。
any one help me to fix this problem...?
任何人帮我解决这个问题...?
回答by Nemoden
There is no way to do it in PHP, use JavaScript instead. That's how your button should be coded in HTML:
在 PHP 中没有办法做到这一点,而是使用 JavaScript。这就是你的按钮应该如何在 HTML 中编码:
<input type='button' value='Close' onclick='javascript: window.close();' />
回答by hypervisor666
Sir,
先生,
Your question is very vague, possibly mis-categorized and difficult to understand.
您的问题非常模糊,可能分类错误且难以理解。
That being said, I will attempt to answer you, although, Algorithm first:
话虽如此,我将尝试回答您,尽管首先算法:
- You have a workflow process where users are entering data.
- You are guiding them through a series of steps, in which you are gathering different bits of information at each step.
- You need to capture the data at each of these steps from a "form" (HTML form, or Javascript Form) and then you need to successfully save the captured data.
- You need to supply the user with feedback on whether the operation was successful or not.
- After the form successfully saves You need to direct the user to another area.
- 您有一个用户输入数据的工作流程。
- 您正在引导他们完成一系列步骤,在这些步骤中,您在每个步骤中收集不同的信息。
- 您需要从“表单”(HTML 表单或 Javascript 表单)中的每个步骤捕获数据,然后您需要成功保存捕获的数据。
- 您需要向用户提供有关操作是否成功的反馈。
- 表单成功保存后,您需要将用户定向到另一个区域。
Just to be crystal clear PHP is a server-side technology that has the ability to send dynamically generated HTML pages to a client's web browser, such as an HTML form, and to process the result of an HTML form that was "posted" back to it.
明确地说 PHP 是一种服务器端技术,它能够将动态生成的 HTML 页面发送到客户端的 Web 浏览器,例如 HTML 表单,并处理“发布”回给客户端的 HTML 表单的结果。它。
PHP also has the capability to do a SQL database "INSERT" to store your information, and then to subsequently evaluate the result of the database "INSERT" query.
PHP 还能够执行 SQL 数据库“INSERT”来存储您的信息,然后随后评估数据库“INSERT”查询的结果。
The idea implied here is the user requests a page that contains a form where they can input data, (this form can just be one step in a series of steps...) the user then inputs their data and clicks the "next" or "submit" button in the form and their browser captures the input and sends it back to the server.
这里隐含的想法是用户请求一个页面,其中包含一个他们可以输入数据的表单,(这个表单可以只是一系列步骤中的一个步骤......)然后用户输入他们的数据并单击“下一步”或表单中的“提交”按钮,他们的浏览器会捕获输入并将其发送回服务器。
The server receives this information on a specific page (specified in the HTML form attribute "action") and has access to the sent data in one of several "super-global" PHP arrays ($_REQUEST[], $_GET[] or $_POST[], which is usually "$_POST" and is specified in the HTML form attribute "method").
服务器在特定页面上接收此信息(在 HTML 表单属性“action”中指定),并且可以访问几个“超级全局”PHP 数组($_REQUEST[]、$_GET[] 或 $ _POST[],通常是“$_POST”,在 HTML 表单属性“method”中指定)。
The PHP script can then process the input: checking for XSS (cross site scripting), SQL Injection attacks, invalid input, etc. and if the input is valid execute a database insert query. After evaluating the result of that query and send an HTML "success/fail" page response back to the original user, or send the user the next HTML page (the next step in the process).
PHP 脚本然后可以处理输入:检查 XSS(跨站点脚本)、SQL 注入攻击、无效输入等,如果输入有效,则执行数据库插入查询。在评估该查询的结果并将 HTML“成功/失败”页面响应发送回原始用户后,或向用户发送下一个 HTML 页面(流程的下一步)。
Javascript (like the code you supplied us with) is a client-side technology (client side ONLY!!!) that executes only in the end users web browser. Using a javascript form to capture user input (as in being able to hold it inside of persistent storage, like a database) defeats the purpose and usefulness of the well-known and "well-lit" path of using HTML forms to POST back to a PHP script/file/method... UNLESS you are talking about AJAX calls.
Javascript(如您提供给我们的代码)是一种客户端技术(仅限客户端!!!),仅在最终用户的 Web 浏览器中执行。使用 javascript 表单来捕获用户输入(如能够将其保存在持久存储中,如数据库)违背了使用 HTML 表单进行 POST 回传的众所周知且“明亮”的路径的目的和有用性一个 PHP 脚本/文件/方法...除非你在谈论 AJAX 调用。
AJAX (Asynchronous JAvascript and XML) is not a new technology or another programming language rather it is using Javascript to make a "behind the scenes" call (on an independent "thread" on the client computer) to a specified PHP script/file/method to get a specific answer and then to insert the answer dynamically back into the current HTML DOM. (partial-page refresh, whole page DOES NOT refresh.) Then using Javascript forms to capture input could be interesting... although somewhat "off the beaten path", due to the fact that the user must have javascript enabled in their web browser in order for your site to function properly.
AJAX(异步 JAvascript 和 XML)不是一种新技术或另一种编程语言,而是使用 Javascript 对指定的 PHP 脚本/文件进行“幕后”调用(在客户端计算机上的独立“线程”上)方法来获取特定的答案,然后将答案动态地插入到当前的 HTML DOM 中。(部分页面刷新,整个页面不刷新。)然后使用 Javascript 表单来捕获输入可能会很有趣……尽管有些“偏离常规”,因为用户必须在其 Web 浏览器中启用 javascript以便您的网站正常运行。
The code that you supplied us with indicates you are using javascript to close the entire web browser window, I'm confused...?
您提供给我们的代码表明您正在使用 javascript 来关闭整个 Web 浏览器窗口,我很困惑...?
I would suggest investigating using Javascript/jQuery to change the "CSS visibility" attribute of an embedded HTML form, combined with some AJAX calls back to the server, instead of a pop-up of some kind, that way you could still use your "click button and input area appears" method, while still having a solid back-end infrastructure in place to handle input, processing and response.
我建议调查使用 Javascript/jQuery 来更改嵌入式 HTML 表单的“CSS 可见性”属性,结合一些 AJAX 调用回服务器,而不是某种弹出窗口,这样您仍然可以使用您的“单击按钮和输入区域出现”方法,同时仍然有一个可靠的后端基础设施来处理输入、处理和响应。
Best of luck! :)
祝你好运!:)
回答by whywhywhy
I beg your pardon but there is a way to do this in PHP via JS:
请原谅,但有一种方法可以通过 JS 在 PHP 中执行此操作:
echo "<script type=\"text/javascript\" charset=\"utf-8\">window.self.close()</script>";
You can do this once all your PHP serverside processing is done.
一旦您的所有 PHP 服务器端处理完成,您就可以执行此操作。
回答by Mike Thomsen
Set it as the click handler
for the button.
将其设置click handler
为按钮。
Plain way:
普通方式:
<input id="save_button" type="button" onclick="closeForm();" value="Save"/>
jQuery way:
jQuery方式:
$("#save_button").click(closeForm);