我們有一個javascript函數應該使用錨將頁面「移動」到某個位置。這個功能只是window.location.href = "#" + hashName
。這適用於FF,但不適用於IE。我在Windows XP下使用IE7測試了這個代碼。 我試過using window.location.href
,window.location.hash
,window.location.replace
和所有這些方法,但使用document
對象。 有誰知道如何處理這個問題?IE7中的window.location.hash問題
6
A
回答
6
IE和大多數其他瀏覽器將滾動到錨與anchor.focus(),或與用element.scrollIntoView(真)的ID的任何元素
2
您是否試過改變location.hash
?
window.location.hash = "#" + hashName;
4
我justed在IE7 Vista下測試了這,也許這個問題只存在於XP下的IE7中?因爲這個工作正常,我在IE7,Chrome和Firefox:
window.location.hash = hashName;
如果這真的不工作,那麼我們可以使用scrollIntoView作爲肯納貝克建議。
function scrollToAnchor(anchorName){
//set the hash so people can bookmark
window.location.hash = anchorName;
//scroll the anchor into view
document.getElementsByName(anchorName)[0].scrollIntoView(true);
}
使用這樣的:
<script type='text/javascript'>scrollIToAnchor('foo');</script>
<a name='foo'></a>
<p>I will be scrolled into view</p>
0
相關問題
- 1. IE7 window.location.hash問題
- 2. 問題w/window.location.hash
- 3. 設置window.location.hash的潛在問題
- 4. IE7中的佈局問題
- 5. IE7中的CSS問題
- 6. @ IE7中的font-face問題
- 7. IE7中的填充問題
- 8. IE7中的z-index問題
- 9. IE7中的Z-INDEX問題
- 10. IE7中的CSS問題
- 11. 在IE7中的CSS問題
- 12. 在IE7中的CSS問題
- 13. IE7中的jQuery問題
- 14. jquery scrollTo IE7中的問題
- 15. IE7的CSS問題?
- 16. Angularjs IE7問題
- 17. jcarousel ie7問題
- 18. jquery ie7問題
- 19. IE7問題
- 20. 問題在IE7
- 21. 在IE7中呈現問題
- 22. 在IE7中呈現問題
- 23. ie7中懸停問題
- 24. 在IE7中溢出問題
- 25. 對齊問題在IE7中
- 26. ie7中navbar懸停問題
- 27. IE7頁腳問題
- 28. 問題與IE7/8
- 29. dojo 1.4 ie7問題?
- 30. IE7 Z-Index問題
來到你是什麼意思與 '使用文檔對象' 的問題嗎?你應該按照答案中的建議使用`window.location` - document.location是Gecko特定的! – Christoph 2009-06-01 13:54:20
我用過他們 - 他們不工作 – 2009-06-01 14:24:57
弗拉基米爾,在IE7/XP中爲我工作... – James 2009-06-01 15:50:02