在window.location.replace(url)之后未调用jQuery代码 [英] jQuery code not called after window.location.replace( url )
问题描述
我有一个代码,单击链接('#versionPageFromProdLink')后,会将页面重定向到索引页面.索引页包含其中的内容.我想在页面重定向后隐藏它,并显示下一个具有()的div.
I have a code that after clicking on a link ('#versionPageFromProdLink'), will redirect the page to the index page. The index page has that contains the content. I want to hide this after the page is redirected and show the next div that i have ().
页面被重定向,但是在window.location.replace(url);之后是jQuery函数.线没有被呼叫.
The page is redirected however the jQuery function after the window.location.replace( url ); line is not called.
页面重定向后如何重定向和调用jQuery?
How will I be able to redirect and call the jQuery after page redirection?
代码:
jQuery( '#versionPageFrmProdLink').click( function(){
window.location.replace( url );
// jQuery code below is not called, <div id="versionMainContent"> is not hidden
jQuery(".versionMainContent").hide("fast", function(){
jQuery( ".versionProductContent" ).show();
});
});
推荐答案
如上所述,location.replace表示将不执行之后"的代码.您需要做的是附加一个哈希值"index.html#divCode"或类似的内容(在这种情况下,您也可以使用查询字符串),然后在索引页面上检测到onload/document-ready,然后进行更新隐藏/显示状态.
As stated, the location.replace means the code "after" it won't execute. What you will need to do, is append a hash "index.html#divCode" or some such (you could also use a query string in this case) and then detect that onload / on document-ready for the index page, then update the hide/show status there.
这篇关于在window.location.replace(url)之后未调用jQuery代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!