重定向后执行一个函数--javascript [英] execute a function after redirecting - javascript
问题描述
好的,我的页面上有一个简单的按钮(MyPage),淡出当前的div(淡入淡出1),淡入另一个淡出淡出(淡入淡出2)。我现在意识到我可能有机会直接从其他地方去那个页面(淡出2)。我可以通过 window.location
重定向我的页面。但是我也希望如果按下该链接(来自其他一些随机页面),请转到页面(淡入淡出1)然后 fadeOut
当前div和 fadeIn
另一个(淡出2)。
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).
希望这不会太混乱。这是我用来访问页面的代码(MyPage):
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');
})
推荐答案
更改 window.location
将终止当前在浏览器中运行的所有脚本。
Changing the window.location
will kill all scripts currently running in the browser.
您唯一的其他解决方案通过 AJAX
获取页面并运行回调函数以在加载内容时执行。 这可以帮助您入门。
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.
另外, jQuery作为一个不错的 .ajax()
方法轻松执行 AJAX
请求并将回调与成功和失败的请求相关联。
Also, jQuery as a nice .ajax()
method to easily perform AJAX
requests and associate callbacks to successful and failed requests.
这篇关于重定向后执行一个函数--javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!