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/