防止Javascript函数中的重定向循环
我得到了一个可通过两个URL访问的ressource,例如:mygoodlookingurl.de/nice.jsf和mybadlookingurl.de/bad123454423523413413.jsf 我必须调用一次外观不好的url,然后我想重定向。目前,我使用JQuery的document-ready()-函数并调用cleanUrl(),该函数通过top.location.href=“mygoodlookingurl.de/nice.jsf”重定向 不幸的是,出现了一个无限循环,因为在onload上加载url之后,函数会被一次又一次地调用。怎么办 下面是JS代码(我使用一个技巧来读取带有创建的锚标记的URL): 提前谢谢 更新:在第一次重定向之后,currentUrl不会更新,因此无限循环仍然会发生防止Javascript函数中的重定向循环,javascript,jquery,redirect,Javascript,Jquery,Redirect,我得到了一个可通过两个URL访问的ressource,例如:mygoodlookingurl.de/nice.jsf和mybadlookingurl.de/bad123454423523413413.jsf 我必须调用一次外观不好的url,然后我想重定向。目前,我使用JQuery的document-ready()-函数并调用cleanUrl(),该函数通过top.location.href=“mygoodlookingurl.de/nice.jsf”重定向 不幸的是,出现了一个无限循环,因为在o
function cleanUrl(){
var cleanedUrl = "https://xxx.xxx.xx:xxx.jsf";
var currentUrl = window.location.href;
if ( currentUrl != cleanedUrl){
top.location.href = cleanedUrl;
}
}
只是把重定向放在某种形式的条件测试中
var cleanedUrl = "https://xxx.xxx.xx/xxx.jsf";
if(top.location.href !== cleanedUrl){
top.location.href = cleanedUrl;
}
谢谢你,杰克,我能同时处理这个问题
return mygoaljsffile.jsf?faces-redirect=true;
在my Bean方法中。您不能为此使用服务器端代码吗?问题是:在第一次重定向后,currentUrl没有更新(请参阅文章中更新的代码)。
return mygoaljsffile.jsf?faces-redirect=true;