Javascript 页面重新加载返回index.php
我正在我的网站中使用此脚本:Javascript 页面重新加载返回index.php,javascript,php,Javascript,Php,我正在我的网站中使用此脚本: <script> //refresh the page once to load slideshow correctly setTimeout(function(){ if(!window.location.hash) { window.location = window.location + '#loaded'; window.location.reload()}}, 1000); </script>
<script>
//refresh the page once to load slideshow correctly
setTimeout(function(){
if(!window.location.hash) {
window.location = window.location + '#loaded';
window.location.reload()}}, 1000);
</script>
//刷新页面一次以正确加载幻灯片
setTimeout(函数(){
if(!window.location.hash){
window.location=window.location+“#已加载”;
window.location.reload()},1000);
当它被执行时,当前URL(http://.../slider/Cycle2/cycle2-tile.php?selection=3%2C4)
)不是重新加载并附加“#”,而是index.php((http://.../#loaded)
)将被加载。为什么会发生这种情况?我如何修复它?您的意思是:
window.location.href=window.location.href+“#已加载”代码>
而不是
window.location=window.location+'#加载'代码>?你能试试这个吗
<script>
//refresh the page once to load slideshow correctly
var currentLocation=window.location.href;
setTimeout(function(){
if(!window.location.hash) {
window.location = currentLocation + '#loaded';
window.location.reload()}}, 1000);
</script>
//刷新页面一次以正确加载幻灯片
var currentLocation=window.location.href;
setTimeout(函数(){
if(!window.location.hash){
window.location=currentLocation+'#loaded';
window.location.reload()},1000);
你能解释一下你希望发生什么吗?通过上面的代码,它似乎做得很好。我想重新加载当前URL(包含脚本),如代码后面的文本所示。相反,index.php加载并附加“#”是index.php中包含的slider/Cycle2/Cycle2-tile.php,如frame、iframe等?谢谢您的回答。是的,我试过了,甚至在所有位置对象之后设置了.href。仍然加载index.php并在其中附加“#”:(我不记得使用window.location.reload重定向页面。是的,这就是问题所在。location.href=足以激活重定向。好的,从所有四个表达式中删除了window对象,现在它保留在同一个窗口中,但“#”仍然没有附加到当前URLMy代码snipet:window.location.href=window.location.href+“#coucou”非常感谢。我真的不明白为什么其他解决方案不起作用。是因为我,还是文档中关于窗口、位置、href对象的内容确实不精确?有人能提供解释吗?@Pete它可能与这个关键字有关