I have a page which contains a form. The form submits via a Javascript call, and it opens a new window via the target set to "_blank".
<div id="ajax_response_html">
<form name="testform_name" id="testform_id" method="post" target="_blank" action="index.jsp" accept-charset="UTF-8" />
<input type="hidden" name="textbox_name" id="textbox_id" value="test" />
</form>
</div>
Upon an onclick event, the form is set inside the above div using an ajax call. At that point, I submit the form in JavaScript.
function setResponse() {
var response = http.responseText;
document.getElementById("ajax_response_html").innerHTML = response;
document.getElementById("testform_id").submit();
}
A new window opens and works just fine. However, I have a mobile app that uses a webview -- a browser session inside the app -- and it does not open a new window. I have no control, at the moment, over the app and no access to its source code. My only recourse is to modify the page to appease both app and non-app users. For the former, it'll open up in the same window. For the latter, it'll open up a new window. That's the plan.
My thought process is to detect if a new window has opened. If not, then I open it up in the same window.
if (!windowOpen) {
// Open page in the same window
}
How can I detect if a new window has opened after submitting the form?
Thank you.
Update
I spoke to the developer of the app, who said he has popups disabled and will not changes any time soon.
I modified the page such that instead of calling the html form file, via ajax, I open this same file using the JavaScript window.open function:
function openForm() {
var formWindow = window.open('FormFile.html', '_blank', 'height=' + screen.height + ', width=' + screen.width');
}
Within FormFile.html, I attached an onload event that submits the form, except the target is set to "_self", not "_blank".
Now, it opens in the same window within the app and opens a new window everywhere else. My question is, since popups are disabled within the app, why would window.open work, yet the original method I was using to submit the form was failing?