iPad safari modalpopup issue - javascript

I am developing a web application which is compatible with iPad.
Earlier I was testing on iOS version 3.2, and all modal dialog popups are returning values just fine to the parent window. But after upgrading my iOS to 4.3, it is behaving odd. Now, on iPad, it is returning a value, but is not updating the field until I click on another field or the same field (HTML text field).
I am opening modal popup using window.open();
And returning using window.opener.oaEventiPad(retValArray);
oaEventiPad is function which is responsible for setting updated value.
Can anyone please help ??
Thanks,

I am through the similar issue. I open a popup suing window.open in my asp .net application which is supposed to be compatible with iPad. Value has successfully been returned when I use IE, Chrome, FireFox and Safari (on PC with windows 7).
Unfortunately the same code fails in Safari when I access the application through iPad. On iPad domObject is prompted on new window open instead of prompting returned value on new window close.
Below is the code.
Parent Window:
enter code here
<script type="text/javascript">
function modalWin() {
//alert('clicked');
if (window.showModalDialog) {
retVal = window.showModalDialog("About.aspx", "name", "dialogWidth:255px;dialogHeight:250px");
alert(retVal);
}
else {
retVal = window.open('About.aspx', 'name', 'height=255,width=250,toolbar=no,directories=no,status=no, menubar=no,scrollbars=no,resizable=no ,modal=yes');
alert(retVal);
}
}
</script>
//HTML
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<a title="Test New Popup" onclick="modalWin();">New Popup for all browsers.</a>.
</asp:Content>
New Page:
<script type="text/javascript">
function closeIt(tempValue) {
window.returnValue = tempValue;
window.close();
}
</script>
//HTML:
<input id="btnButton1" value="btnButton1" type="button" title="Press it to Close" onclick="closeIt('btnButton1');" />
<br />
<input id="btnButton2" value="btnButton2" type="button" title="Press it to Close" onclick="closeIt('btnButton2');" />
<br />
<input id="btnButton3" value="btnButton3" type="button" title="Press it to Close" onclick="closeIt('btnButton3');" />

Related

How to close the webpage on its own on clicking a button

I have a page where a <button> is kept on which onClick() event fires and redirects the new page in new tab. Meanwhile I want the parent page to close itself as soon as the <button> is clicked with opening the new page in new tab. Its basically for some security feature for the website. How can this be done?
Here is my <button>, let me know where can i correct myself.
<button formtarget="_blank" type="submit" name="submit" onClick="javascript:window.open('quiz.php?unit_id=<?php echo $fnc->encode($unit_id) ; ?>');self.close();" value="submit" class="btn btn-info" style='margin-left: 35%;margin-bottom: 10px;' ><i class="glyphicon"></i> Start Quiz</button>
you can close window by below function
function close(){
setTimeout("window.close()", 500);
}
But keep in mind that : Scripts may close only the windows that were opened by it.
The window close and open new tab
<script language="javascript">
function quitWindow(cmd)
{
if(window.open("your_new_tab_page.htm")){
if (cmd=='quit')
{
open(location, '_self').close();
}
}
return false;
}
</script>
<input type="submit" onclick="return quitWindow('quit');" value="Close This Window and open new Tab" />
If you use firefox, you should about:config by writing url bar and set
dom.allow_scripts_to_close_windows = true
otherwise does not work firefox
I think this might work.
<script>
function openWindow( url )
{
window.open(url, '_blank');
window.focus();
window.close();
}
</script>
<button onclick="javascript:openWindow(yourHref);return false;">Submit</button>
You cant close your webpage if the user clicked the link of your website from any other place other than your website, due to security reasons.

Form submit not working in Javascript function after innerhtml update

I have a Javascript function called from a OnClientClick which is changing a forms action. The reason for this is there are other buttons on the form but only one of them is required to do the postback. I would like the target of the postback to open in a new window whilst altering the content of the sender form using div.innerhtml="Some HTML Code HERE!"
I have managed to write a function that works in Chrome, IE and Opera but I cannot get it to work in Firefox. As soon as I add the code to change the content of the Div for some reason the Form.Submit does not appear to happen. The content of the div updates but the new window does not open. If I remove the innerHTML edit from the code below the submit works and new window or tab opens as required. This problem on appears to occur in Firefox.
This is my code.
<script type="text/javascript">
/* Used to change form submission to another address , by dynamically setting a buttons OnClientClick property on server side */
function SetFormAction() {
var frm = document.getElementById("form1");
var paybut = document.getElementById("altCtButton1");
var canbut = document.getElementById("altCtButton2");
var altdiv = document.getElementById("divAltContent");
frm.action = "http://www.awebite.com";
paybut.disabled = "disabled";
canbut.disabled = "disabled";
frm.target = "_blank";
altdiv.innerHTML = "<br /><p>Process has been started, please complete in the new browser window and return to the jobs list when done!</p>" +
"<p><a href='/mysite/apage.aspx' class='btnType2' >Jobs List</a></p><br />";
frm.submit();
return false;
}
</script>
So the function above is called on a OnClick event in from a submit button within the browser. It changes the action of form1, disables the button that called it then for paranoia changes the content of the div that contained the button.
Any help with why this function does not work in Firefox would be appreciated.
So, the markup which calls this function is from a div which rendered from vb code behind but looks like this:
<!-- ShowAltContentMessage() Template ASPX Code Block - BEGIN -->
<div id="divAltContent" class="box">
<div class="content">
<input type="hidden" name="altCtStateData" id="altCtStateData" />
<span id="altCtHdrLabel"><P><B>Proceed to Payment Details Entry?</B></P></span>
<span id="altCtBdyLabel"><P>It appears a process was previously initiated however it may have been cancelled, please ensure you are not making a duplicate process.</P></span>
<span id="altCtFtrLabel"></span>
<input type="submit" name="altCtButton1" value="Yes - Process Job" onclick="SetPaymentServiceAction();" id="altCtButton1" class="btnType2" />
<input type="submit" name="altCtButton2" value="No - Abort" id="altCtButton2" class="btnType2" />
</div>
</div>
<!-- ShowAltContentMessage() Template ASPX Code Block - END -->
Whats interesting is if I remove the line of code:
altdiv.innerHTML = "<br /><p>Process has been started, please complete in the new browser window and return to the jobs list when done!</p>" +
"<p><a href='/mysite/apage.aspx' class='btnType2' >Jobs List</a></p><br />";
From the Javascript function everything works in Firefox with the exception of the content updating. I.E the new window or tab opens with the new web address and the buttons get disabled.
As I mentioned this code works perfectly in Chrome, IE and Opera so appears to be a browser specific issue?
Thanks

Navigate new page in same tab/window using button

I've been trying to navigate a page to another page in the same window (web browser = Google Chrome, Mozilla Firefox and Internet Explorer) using button. The steps are,
The page will popup message for confirmation.
If the user click ok, then the page will navigate to other page in the same tab/window.
If the user click cancel or x, it stays on the current page.
I have tried using
window.open("home.php","_self"); and window.location.href="home.php"; and document.location.replace("home.php"); and location.replace("home.php"); and location.assign("home.php");
but it doesn't work. How do I fix this?
<span title="Click to register the new user"><button type="submit" id="submit" onclick="myFunction()">Register User</button></span>
<script>
function myFunction() {
confirm("Proceed?");
window.open("home.php");
}
</script>
Problem seems to me is, possibly you are using form with button which leads to reload.
<button type="submit" id="submit" onclick="myFunction()">Register User</button>
Make the type="submit" to type="button". Also major browser do have popup blocker enabled where this line may fail window.open("home.php");
Small change in script as follows:
function myFunction() {
if(confirm("Proceed?")) //<--- ok/yes = true, no/cancel/close = false
location.href = "home.php";
}
Small demo:
var ask = function() {
if (confirm('Proceed ?'))
location.href = "http://espn.go.com/";
};
<button onclick="ask();">Watch ...</button>
window.location.href
is not a function . You have to use it as
window.location.href="home.php";
Updated your code and this works
<span title="Click to register the new user"><button type="submit" id="submit" onclick="myFunction()">Register User</button></span>
<script>
function myFunction() {
if( confirm("Proceed?") )
window.location.href="home.php";
}
</script>

After Closing Print Preview on web page, Javascript function of closing window does not work properly on IE

I posted this question at the end of the workday as my brain was melted.Please help me.
I have a web page, calling a JavaScript Function from an Event Handler.
The JavaScript Function is used to close window.
Like this:
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
function closeWin() {
window.opener = null;
window.close();
}
</SCRIPT>
</HEAD>
<BODY>
<FORM>
<INPUT TYPE="button" VALUE="Close Me"
onClick="closeWin()">
</FORM>
</BODY>
</HTML>
This web page is needed to run in Internet Explorer(I use IE7).
When I clicked "Close Me" button,the window would be closed.
My Problem is -
(1)Right-Click on the page and select Print Preview...(Print Preview Page will be shown)
(2)Close the Print Preview Page by clicking on the CLOSE(x) button
(3)And Then click "Close Me" button,the window will not be closed.
So,I don't know how to solve this problem so that the web page close properly by "Close Me" button after viewing Print Preview??
In step (2) -
(2)Close the Print Preview Page by the escape key on keyboard ( Esc )
(3)And Then click "Close Me" button,the window will be closed properly.
I am a beginner at JavaScript and I don't know much about how this problem occurred.
this will open the preview window and print dialoge
<script type="text/javascript"><!–
function ClickHereToPrint(){
try{
var oIframe = document.getElementById('ifrmPrint');
var oContent = document.getElementById('divToPrint').innerHTML;
var oDoc = (oIframe.contentWindow || oIframe.contentDocument);
if (oDoc.document) oDoc = oDoc.document;
oDoc.write("<head><title>title</title>");
oDoc.write("</head><body onload='this.focus(); this.print();'>");
oDoc.write(oContent + "</body>");
oDoc.close();
}
catch(e){
self.print();
}
}
// –></script>
This is a known bug in IE 7, 8 and 9. See this

javascript form onload doesn't work in Safari

My goal is to open a new window when the user clicks on the link and then reload the main page to go back to the previous content. The first code snippet below works in IE and FireFox but doesn’t pop a new window in Safari. The second code snippet works in all 3 browsers but in Safari doesn’t perform the history.go(-1); to go back to the previous page on a main window.
Also, in a second snippet, if I put "return true;" after "history.go(-1);" history.go(-1); does work but the new window doesn't pop up (target=""_blank"").
Any suggestions?
Thanks,
Ryan
<html> <body> <form id="sso" method="POST" action="/apps/Integration/SsoUtil/SiteTransfer/SsoSignonSaml2Url.aspx" target="_blank" >
<input type="hidden" size=150 name="SsoEncryptedData" value="<%=cd.ToSsoEncryptedB64()%>" /> </form> </body>
<script>
sso.submit();
history.back(); </script> </html>
------------------WORKS IN SAFARI BUT DOESN"T RELOAD THE PARENT PAGE-----------------------
<%
Response.Write("<html>")
Response.Write("<body onload=""document.getElementById('sso').submit();return true; history.go(-1);"">")
Response.Write("<form id=""sso"" method=""POST"" action=""/Apps/Integration/SsoUtil/SiteTransfer/SsoSignonSaml2Url.aspx"" target=""_blank"">")
Response.Write("</form><br/>")
Response.Write("</body>")
Response.Write("</html>")
Response.End()
%>
-------------------------------------------------------------------------------------------
Try
<script>
sso.submit();
setTimeout(function() { history.back();},1000)
</script>
then try returning <script>opener.history.back()</script> from your server when you submit
Lastly give your form a submit button and try clicking it instead of submitting the form
document.getElementById('subbut').click()

Categories

Resources