Refresh one php page from another page - javascript

I have one PHP page(dashboard.php). on click on a button it opens up one pop up page(viewstatus.php).I updates some data on this page and click submit button on this page it updtes the data and close this popup and refresh the page dashboard.php.But my page dashboard.php is not refreshing. This is the code written on the file viewstatus.php.
$query->execute();
$_SESSION['msg']="Stationery Added successfully";
header("Refresh:0; url=dashboard.php");
echo "<script>window.close();</script>";

Try this please:
$query->execute();
$_SESSION['msg']="Stationery Added successfully";
header("Refresh:0; url=dashboard.php");
echo "<script>window.opener.location.reload();window.close();</script>";

The reason the page is not refreshing is because the header is redirecting the popup page, not the dashboard page.
Refreshing the page on demand is going to be pretty difficult.
When you open the popup you can save that variable in javascript and add an onclose listener, but this is not supported in all browsers.
var popup = window.open('...');
if (popup) {
popup.onclose = function(){ window.location.reload };
}
Another way would be in your popup window to add the following code:
window.opener.location.reload();
Just add that above the window.close(); that you put in your example code and it might work.
It worked for me, but just as the other one I don't know if this is supported by all browsers.

Related

how to avoid refresh page or back button click when popup is open using jquery?

I am developing one stepwise form application where I am displaying some information on Modal popup. I am able to display the required information. If I refresh the page when the Modal is open the current Modal will close. Is there any way to stop closing the Modal on page refresh?
You can not prevent user clicking the refresh button.
Instead you can keep the state of the form in the local storage and in the page load event check if the user was in the middle of the form process.
If so, just show the modal again. There's no any other way.
//This is an example. This should be added when the user seen the dialog.
//This is just a Bootstrap example. Just to demonstrate the logic.
$("#modal-dialog").on("shown.bs.modal", function(){
localStorage.setItem("IS_SET", true);
});
$("#modal-dialog").on("hidden.bs.modal", function(){
localStorage.setItem("IS_SET", false);
});
$(document).ready(function(){
if(localStorage.getItem("IS_SET") && localStorage.getItem("IS_SET") === true){
//Which means the user was in the form process.
//And show the modal again on page refresh.
$("#modal-dialog").modal("show");
}
});
If you don't like the localstorage method, you can set a URL param which can be seen publicly in the URL.

Open Webpage Section/Tab on Form Submit / page reload

I am using a bootstrap theme and am trying to get my page's form to stay on/open the specific registration form's confirm message. Unfortunately with several Registration Forms on the page, each is "hidden" inside it's own hidden div/tab. I am not too good with JS and have spent about 4 hours so far trying to get this to function properly:
http://middlechambersociety.com/dev/mcs2014/
On any Registration Form completion I want the user to be brought back to and shown that Registration Form's Confirmation Message AND the "Pay with Card" button when it is part of the reg process (the button currently shows when it should). However, the problem is that when my form reloads the best i can do is bring users to the Registration Section and show the Golfer's Reg Form and/or Confirm message only (because it is the default open div/tab). I have tried php and limited JS/jQuery with no success. I have tried adding Class .active to the li i want to display but no luck. I currently have the following trying to fire on each form when submitted to TRY to get the appropriate registration tab to display:
<?php
if ($reg_type == 'Diners' && !empty($confirm_msg)) {
?>
<script type="text/javascript">
alert('Working1');
$(document).ready(function() {
alert('Working');
var tab = $('#reg_diner').parent();
alert(tab);
tab.addClass('active').siblings().removeClass('active');
});
</script>
<?php
echo '<div class="confirm-message">' . $confirm_msg . '</div>';
echo $stripe_pay_form;
}
?>
please help.
For anyone who may be confused as to what i am looking to accomplish: feel free to complete one of the forms (Dining for instance) and see that the confirm message is hidden until you PHYSICALLY navigate back to the Dining registration tab.
Maybe try an ajax call and on success add active class to new content?
My bad - misunderstood. Heres where I can see your error:
In console.log You've got an $ reference error at your script calling point. Cause you load jQuery in footer. So it cant use scripts before it load fully. (Document Ready doesn't work because he doesn't know this command yet) Put jQuery into head, or your tag after calling jQuery
I understand not wanted to navigate user to a different page but sometimes it is just much easier.
One way though would be to put a $_GET string in the form post then use that to control the display message. Add it to the form action url maybe:
enter code hereaction="index.php?form=golfer1"
Then update your code :
<?php
if ($_GET['form'] == 'golfer1') {
echo '<div class="confirm-message">' . $confirm_msg . '</div>';
echo $stripe_pay_form;
}
?>

Javascript refresh main page after closing child window (popup)

I have 3 php files: view.php, edit.php and edit2.php.
I use view.php to display content of my DB tables, edit.php to edit a specific row (I use textboxes etc.) and edit2.php to write any changes to my database. After the query is successfully executed, edit2.php uses header("Location: edit.php"); to display the chosen row again (I use session variables in edit.php and unset them on view.php).
edit.php and edit2.php are opened in a small popup window. Now what I would like to have is when I close my small window, view.php should be refreshed.
I tried using onunload but what it does it is triggers itself each time a button is clicked in edit.php to send data to edit2.php, so when it returns to edit.php, it's blank because session variables are unset due to refreshing of view.php.
I have this strange feeling, that I might have explained it in a twisted way... Nevertheless, I would need some help.
What you want to do is open a new window using window.open('edit.php')
Here is the documentation for window.open()
Then watch for when the new window is closed, and refresh the page when that happens. Unfortunately there is no 'on close' event that's fired, but there is a property window.closed that you can watch to see when the window is closed.
So this is what you should do:
var win = window.open('edit.php','Edit Row','width=800,height=600,status=0,toolbar=0');
var timer = setInterval(function() {
if(win.closed) {
clearInterval(timer);
location.reload()
}
}, 1000);

Refresh Parent page when closing a fancybox2 iframe

I am using an Iframe with fancybox2, to open up a page which has a form which updates a database. What i am looking for is that when the fancybox is closed the parent page, which is a table of database results, automatically refreshes it's self.
My link to the iframe page is here:
echo "<a class='fancybox fancybox.iframe' href=\"add.php?ip_address={$ip_address}&id={$id}&userna={$username1}\" class=' btn btn-small' data-original-title='Add'>Add</a>";
I also have this code which i found in a different post, when i include this in the parent page, and click on the link, the fancy box starts but then immediatley closes and refreshes the page.
$("fancybox").fancybox({
afterClose : function() {
location.reload();
return;
}
});
I have tried several re-writes of this code but it either describes as above or just doesn't work. Any suggestions would be much appreciated.
try calling window.parent.location.reload();

Parent Jsp page refresh when click on popupwindow alert box

I am working on jsp's, I have two jsp one in configDb.jsp, in that I have written code to retrieve the values from database and display it. In this whereas I have option like newconnection.. its a popup window. When I click on that it opens popupwindow and taken the values and store them in a database, but in my parent page I am not able to display those values. After I click on the ok button in popup window, I have to refresh the parent page, then I am able to see the values which I have created few seconds back by the new connection page. Could anyone please help me out?
You can include this in your HTML for the popup window.
<script type="text/javascript">
function proceed(){
opener.location.reload(true);
self.close();
}
</script>
<form onsubmit="proceed()">
...
</form>
Actually you can obtain the answer by googling "javascript refresh parent page from popup" and you will see stackoverflow's answer :)
A better alternative without the need of refreshing the parent page can be achieved by adding a submit button listener and perform a DOM action to insert the new element with new content. This can be easily done by Javascript.

Categories

Resources