javascript form onload doesn't work in Safari - javascript

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()

Related

Submit form and close window

I can't understand why this isn't working.
I have a form opened in new tab, which I want to close when submitting:
<form name="form" id="form" method="post" enctype="multipart/form-data" >
//form inputs
<button accesskey="C" class="boton" onclick="form.submit(); alert('waiting...'); window.close()"> <u>A</u>djuntar</button>
</form>
when I remove window.close() the form is submitted, but when it's in my code, it shows the alert but not submitting.
Is there anything wrong?
you don't have to open the form in a new window (or tab).
you can either submit the data in ajax or use an inner hidden iframe as the target property of the form element. this way the form will open in a hidden inner element. e.g.:
<form id="eFrm" target="ifrm1">
</form>
<iframe id="ifrm1" name="ifrm1" style="display:none"></iframe>
The form won't be submitted until the event handler function has finished running.
alert blocks all execution of everything until the dialog is dismissed.
close closes a the window, so there is nowhere to load the form submission into, which cancels the request.
If you are going to close a window, don't expect it to be able to send an HTTP request at the same time.
You probably already found a solution, but I am posting this anyway for anybody who comes across the same in the future.
I am using Java servlets, but I think that is the same with every form submission => ability to choose which page must be displayed after the posted data was processed.
Once I have submitted the form, the doPost method in the servlet allows me to say which URL I want the browser to display after the data has been processed.
So, you can do probably do something along these lines:
request.getRequestDispatcher ( "/ClosePopup.html" ).forward ( request, response );
Then also create a file called ClosePopup.html, with nothing but a close () instruction
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body onLoad = "window.close();">
</body>
</html>
This way it won't be the button you click to trigger the closure of the popup, but you will be loading a self destroying page after the form is submitted. The final result is identical.

window.open how to open self in Mozilla and IE

so I´m trying to make window.open function work, however I am not able to see it working correctly in Mozilla neither in IE, in both is opening a new tab, however it works correctly in Chrome,.. Here´s the thing:
<input type="submit" value="<%=I18n._("Register")%>" onclick="window.open('http://url.com')" class="button" />
I´ve tried almost everything I guess: location.href, window.self.. etc but nothing seems to work. How can I open this in self?
Thanks in advance.
You are canceling the navigation by submitting the form. You can do the following to prevent the default action (submit the form) and do the navigation instead:
<input type="submit" onclick="window.location.href='http://url.com'; return false;" class="button" />
I removed the value because you're not submitting the form anyway. Feel free to put it back if you use it for anything else, it shouldn't break anything.

HTML button onload submit

I have a button example below
<button id="startrunning">go</button>
There is no form or anything I'm using on the same page java script to detect it's click. It will work like I want it to when I click it. I want to see when the page is loaded it will automatically submit it's self is there a way?
Thank you
jsFiddle: http://jsfiddle.net/QEu84/10/
<script type="text/javascript">
function submit()
{
document.getElementById("startrunning").click(); // Simulates button click
document.submitForm.submit(); // Submits the form without the button
}
</script>
<body onload="submit()">
<form id="submitForm">
<button id="startrunning">go</button>
</form>
</body>
You can automatically click it when the page loads, using the code below, but you need a form to submit something (you submit a form, not a button)
<body onLoad="document.getElementById('startrunning').click();">

How to close popup and redirect a page

My site using php and i create an online quiz and the quiz show in pop up mode.
Currently when i want to redirect my page using the script below. it goes to my homepage BUT it still at the pop up mode. I want it to close the pop up and go to homepage after I click finish.
How can I do that?
<script type="text/javascript">
window.parent.location = "../../../"
</script>
You can access the window that opened a popup with the window.opener property on the popup. So, something like this should work:
window.opener.location.replace(redirectUrl);
window.close;
If you wanted to put that behavior in the onclick event on a submit button you're building like this:
echo "<input type=\"submit\"
name=\"finishattempt\"
value=\"".get_string("finishattempt", "quiz")."\"
onclick=\"$onclick\" />\n";
You'd need to assign the String window.opener.location.href='someUrl';window.close(); to the variable $onclick before echoing the submit button out.
You can try this code (used on an HTML button):
<input type="button" onclick="parent.window.opener.location='http://homepage.com'; window.close();">
And have a look at some similar threads like this one: Javascript: Close Popup, Open New Window & Redirect
[EDIT] See this article too
this way you can do it ..
<script type="text/javascript">
function close_window(){
window.opener.location = 'pop_up.php';
window.close();
}
</script>
html code..
<body>
<form method="post" name="frm_2" id="frm_2">
<input type="submit" name="btn_close" id="btn_close" onclick="return close_window();" />
</form>
</body>

javascript pop-up box

OK so I haven't messed with JavaScript in a long time but I do remember some. I have tried Google but it hasn't proved to be what i wanted.
Let's say I have a link... when you click it -- a window pop-up box appears. You can submit the form... then when you press submit! The pop-up box with the form you just filled out would close and the page you clicked the box up box would be redirected....
How would I make that happen?
Try this:
Parent page:
<script type="text/javascript">
window.name="dansMainPage";
function popWin(link) {
var w = window.open(link.href,link.target,'width=500,height=600,resizable');
return w?false:true; // if popup blocker, use the default behaviour of the link
}
</script>
<a href="pagewithform.html" target="_blank"
onClick="return popWin(this)">Pop form</a>
child page:
<form target="dansMainPage" onSubmit="setTimeout(function() { window.close() },1000)">
.
.
.

Categories

Resources