最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - javascript window.location id - Stack Overflow

programmeradmin0浏览0评论

I want to make the browser to scroll the div's id

<div id="test">
   lol
</div> 

So I use this code

window.location = "#test";

but my url now is like this

http://locahost/index.html#test

Is it possible to delete "#test" but go to that ?

I want to make the browser to scroll the div's id

<div id="test">
   lol
</div> 

So I use this code

window.location = "#test";

but my url now is like this

http://locahost/index.html#test

Is it possible to delete "#test" but go to that ?

Share Improve this question asked Jul 5, 2013 at 4:49 user1128331user1128331 7274 gold badges10 silver badges20 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 7

Scroll to the element:

document.querySelector('#test').scrollIntoView();
发布评论

评论列表(0)

  1. 暂无评论