添加一个散列与JavaScript的网址,而无需滚动页面? [英] add a hash with javascript to url without scrolling page?

查看:122
本文介绍了添加一个散列与JavaScript的网址,而无需滚动页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为网址添加散列而不滚动页面?
with javascript


  1. 我打开页面

  2. 向下滚动

  3. 我点击添加哈希的链接(也许值为#test)(例如: http: //www.example.com/#test

  4. 页面不能滚动回页首。

这怎么做?



注意:
只是检查是否可以禁用移动,即使有一些标签id =test
到目前为止返回false;可以正常工作(支持没有javascript的人),也可以避免在html中出现id,但它不会像数字那样出现问题,比如1,2,3(它们不允许作为id使用)



所有的答案都很棒,没有什么新意或突破性的,并且没有解决方法来打破默认功能,但它会做。 :)
感谢您花时间回答。

解决方案

页面上不存在的任何散列应该给你这种行为。例如,这个链接指向一个non- existant hash 在此页面上。 (使用Chrome 2.0和IE 6进行链接测试(目前我唯一可用的浏览器)。)

所以如果您的URL导致您转到页面顶部,请确保您的页面上没有任何内容,其ID或名称是该地址。


add a hash to url without scrolling page? with javascript

  1. i open page
  2. i scroll down
  3. i click link that adds a hash (maybe with a value #test) (example: http://www.example.com/#test)
  4. the page MUST not scroll back to the top.

how can this be done?

note: just checking if it's possible to disable the movement even if there is some tag with id="test" so far the return false; works fine (to support people without javascript), and also to avoid the presence of the id's in the html, but it is not a problem with things like numbers, like 1, 2, 3 (they are not allowed as id's anyway)

all the answers are great, nothing new or groundbreaking, and no solutions on how to break the default functionality, but it will do. :) thank you for taking the time to answer.

解决方案

Any hash that isn't present on the page should give you this behaviour. For example, this link points to a non-existant hash on this page. (Link tested with Chrome 2.0 and IE 6 (the only browsers I have available to me at the moment).)

So if your URL is causing you to go to the top of the page, make sure you have nothing on the page whose id or name is that address.

这篇关于添加一个散列与JavaScript的网址,而无需滚动页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆