refreshing current page when face box fades - php

I have a link that has a rel="facebox". When it is clicked it runs a php script from a separate file. I want to refresh the page automaticaly when the facebox fades. How can I do it? I've tried the headers and metas but it is not working.

You can bind event afterClose.facebox:
$(document).bind('afterClose.facebox', function() {
location.reload();
});

Related

How can I call a click event from another file?

i need to call a click event from another file...
On my index.php I have a 'select' to choose a name, once I did, I call by Ajax a form by the name I choosed before, this form is on espacio.php, once I complete the form I must have to click a button to save the info, when I click this button the info are passed by Ajax to espacio2.php and there is here where I show a success or a failure message.
This message shows on my index.php and this is good, but I want to hide it after a few seconds.
How can I call the click event from espacio.php?
This is a code that works only if a click is pressed on the same page:
$(document).ready(function(){
$(".botoncete").click(function(){
$(".prueba").fadeIn();
Esconder();
});
function Esconder(){
setTimeout(function() {
$(".prueba").fadeOut();
},2000);
}
});
I've already solved the problem, thanks to #Barmar, and as he said: "If you're sending the data by AJAX, you stay on the same page".
I really don't know what was I thinking...

How do I prevent a div, which is created by clicking on a button, from disappearing when reloading the page?

I'm using a button to slide down a div which contains a registration form but after I reload the page (or submit the form), the div vanishes and I have to click on the button again. I want the div to stay after reloading the page. Any suggestions?
Here is my jquery code:
<script type="text/javascript">
$(document).ready(function(){
$("button#button_register").click(function(){
$("#register").slideDown('slow');
});
});
</script>
And the button:
<button id="button_register">Register! </button>
You need to somehow save the state of your #register element. You can use server side for this (session) or a simple cookie.
But handling cookies in pure JS is a little bit tricky. Assuming you can use this great plugin: https://github.com/carhartl/jquery-cookie you could do something like this:
$("button#button_register").click(function(){
if($("#register")is(':visible')) {
$("#register").slideUp('slow');
$.cookie('registerState', 0);
} else {
$("#register").slideDown('slow');
$.cookie('registerState', 1);
}
});
... than you need to check for this state every time the page is loaded, like so:
$(document).ready(function(){
if($.cookie('registerState') == 1) {
$("#register").show(); // or slide down if you want to show an animation every time
}
});

Firefox is not finishing ajax request when asked to print page

Here I request print after I insert into a mysql db that the page was printed(I did not find a way to trigger the insert after the page is printed so I put it before), which is inside a $(document).ajaxComplete() block:
$("#bPrintIes").off().on("click",function(){
if(confirm("Confirmati Printarea!")){
var codCom=$("#codCom").val();
$.ajax({
type:"POST",
url:"php/facturi/iesirePrintare.php",
data:{ies:"print",codCom:codCom}
}).done(function(){
window.print();
});
}
});
#bPrintIes is a button, in case you needed to know.
First issue is that it shows a second dialog which asks the user to
"block future messages".
Second issue is that prints another blank page.
The issues are inside Firefox and IE, Chrome does it's job.
I want to show the print dialog and when I press Ok/Accept it should print the page, without the dialog to "block future messages" from the page and without the blank page.
I am ussing JQuery 1.10.2.
Any ideeas/suggestions?
Thank you.

Loading pages into a div with JQuery, existing Javascript not working

I have a page I'm working on where a user clicks a link and it loads a new php file into an existing div. It works but the page that loads into the div will not function with existing Javascript stuff in the page.
I can include the
<script type="text/javascript" src="js/admin.js"></script>
into the loaded pages but when you flick back and forth between the pages I notice that RAM usage starts to go up and up, so I don't think this is the best way of doing it.
Any ideas how the loaded page can function with the already-loaded javascript from the index page?
Thanks!
bind your events like this :
$(document).on({
"event" : function(e) {},
...
}, "selector");
If you are using bind or click type events change to using something like on (or live or delegate if you are required to use jquery version less than 1.9)
OR/AND
In your function that loads in the page via ajax provide a call back that initiates only what is needed. Example:
$('#myDiv').load('ajax/page.php', function(){
$('#myDiv a').customPlugin('whatever');
$('#myDiv button').bind('click', function(){
window.open('http://www.google.com/', 'some-window');
});
});

Disable jQuery effect on page refresh

Overview
I have div#lead_form that SlideDown in 5 seconds after page loads. And in that div, I have a submit button. Everytime someone clicks submit, the form within #lead_form will validate the input fields and refresh the page.
Issue
Everytime the form validates, it refreshes the web page and the div#lead_form SlideDown takes 5 seconds to slide in. What I want to do is, have a true false variable and check if the submit button has been clicked, if true, disable the div#lead_form SlideDown effect?
My HTML
<div id="lead_form">
<div id="button"></div>
</div>
My jQuery
$(document).ready(function() {
$("#lead_form").hide(0).delay(4000).slideDown(5000);
});
Findings
This is not exactly what I'm after, but similar?
In your server side code check if the request is coming with your form submitted, and write the result as a javascript var in a given section on your page
if( isset($_POST['yourFORMFIELD']) )
{
echo "var postBack = true;";
}
then change your jQuery ready to
$(document).ready(function() {
if(!postBack) {
$("#lead_form").hide(0).delay(4000).slideDown(5000);
}
});
As there is a page reload you can not solve this using javascript only.
you have to somehow persist the state (if the form was submitted) and check that state after the page is reloaded.
you can do this either via a cookie or the local storage (local storage will only work in most recent browsers)

Categories