Namit Namit - 1 month ago 4
Javascript Question

execute a function after redirecting - javascript

Okay, i have a simple button on my page (MyPage) which fades out the current div (fade 1) and fade in another one (fade 2). I have now realised that there might be chances that i would want to go to that page (fade 2) from somewhere else directly. I am able to redirect my page by

window.location
. However i also want that if that link was pressed (from some other random page), go to page (fade 1) and then
fadeOut
the current div and
fadeIn
another one (fade 2).

Hope this isn't too confusing. This is the code i am using to get to the page (MyPage):

$('#fav').click(function(){
window.location = 'production/produc_order.php';
$('#view_production').fadeOut('slow');
$('#create_order').fadeIn('slow');
})

Answer

Changing the window.location will kill all scripts currently running in the browser.

Your only other solution is getting a page via AJAX and run a callback function to execute when the content is loaded. Here is something to get you started.

Also, jQuery as a nice .ajax() method to easily perform AJAX requests and associate callbacks to successful and failed requests.

Comments