开发者

Link to page coordinates

Is there a way to link to another page's content using coordinates, without using #anchors? For example, say I want the link to 开发者_运维问答go directly to content that's 1200px down the page. How can I do this? Javascript, server-side magic, anything goes as long as it will work for the average visitor.


Store the coords in a hash

e.g. http://example.com/page#123

Then via javascript, scroll the window

window.onload = function(){
  var pos = window.location.hash.substring(1); //get hash & remove #
  window.scroll(0,pos);
};


You could develop a browser plugin or extension that would allow you do it, for the people who've installed it at least. Otherwise, no.


If you have control of the other website, you could write a javascript that looks at the query string for a parameter (i.e. ?y=1200) and scrolls the page to that position, but I'm guessing you don't have access to the other site?


This can be done with UserJS (Greasemonkey):

http://stackoverflow.com/##scroll-y:1200

But users must install script before.


The browser same origin policy will prevent you from scrolling a frame or iframe displaying content from a different domain. The most reliable method would be to have your server fetch the page and insert the scrolling code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜