javascript - 如何在子窗口打开时停止重新加载父窗口

标签 javascript jquery struts2 popupwindow

I have a form submit, where it get the values from the form and goes to next page... here I have a hyperlink to open a child window, while I click, it opens the child window and simultaneously it reloads the parent window. I have a action configured to the parent window which has a Database insert statement too.

The problem is that while I click the link it call my action again(because of page reload), in this action I wrote if condition to check null/empty string from the previous page form submit. since this is the second time the action loads it looks of the fields(but actually those fields are in my previous page form). so it take null while checking my if condition.

Another problem is that when I solve the above problem here comes the SQL insert statement, which is about to execute 2nd time. I dont want this to happen or I dont want my action to execute while I open the popup window and I want to populate the selected value from the popup to the parent window.

用于打开弹出窗口的代码

 function select_reactant()
    {
        window.open ("SeriesTab.action?component=reactant",
            "mywindow","scrollbars=1,resizable=1,width=1000,height=1000");  
        };

这是我打开弹出窗口并希望将从弹出窗口中选择的值填充到此处的文本文件的地方

<tr>
    <td><a href="" onclick="select_reactant();">reactant</a></td>
    <td><s:textfield name="reactant" id="reactantId" readonly="true" theme="simple"/></td>
  </tr>

jquery 取回父窗口弹出的值

$(window.opener.document).find('#reactantId').val(rxn);

下面action里面的代码就是我开头说的action

if(Rxn!=null||!Rxn.equals(""))  //Rxn is the field variable for previous page
{ 
//my insert statement
}

当我运行时出现空指针错误,因为 Rxn 的值由于由

完成的弹出窗口重新加载而被重置为空
window.open 

最佳答案

你可以这样做

HTML

<a href="#" id="anchSelectReactant">reactant</a>

jQuery

$(function(){
    $("#anchSelectReactant").click(function(){
        select_reactant();
        return false;
    });
});

关于javascript - 如何在子窗口打开时停止重新加载父窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8710275/

相关文章:

javascript - 如何更快或同时申请类(class)?

java - 从多重选择中设置多个 javabean 属性

javascript - 如何在struts 2的action中获取jsp中生成的表的值?

javascript - 在 window.open 打开的窗口中滚动到没有 ID 的元素

javascript - Flow 不会提示不正确的类型

php - 使用 Javascript 更新数据库

javascript - 从用户输入生成 json 数据(文本区域)

javascript - 如何在jquery中改变宽度

javascript - 显示和隐藏表中的特定行

Struts2 : How to access session variable in JSP?