0

Is it possible to make a shortcut go down to the part I want it to through a link even if there are no nearby elements with IDs? I have tried this so far:

<a href="http://example.com/#+200px">Go down 200 pixels</a>
<!-- for some reason this doesn't work???? (jk i know its ridiculous) -->

One requirement is that I do not have access to the website I am linking to, it is external entirely. My question is, is the only thing the anchor tag (or similar) can do is scroll to an element with a specific id? For example: this currently works: https://stackoverflow.com#footer because stackoverflow's footer has an id of footer.

But what if no id's exist on any nearby elements.

Answers with other frameworks are welcome, although likely irrelevant.

omikes
  • 8,064
  • 8
  • 37
  • 50
  • 1
    I think any framework or scripting is totally irrelevant here as you'd like to have impact on a website that is not yours. So the question is merely if there is a way to put some parameter into a url that a browser understands as a command to scroll to a specific position on that external page after loading it. I'm afraid there's no way doing such thing unfortunately. – tom Jun 03 '18 at 02:43
  • I feared so. Put that as an answer and I’ll lock it in. – omikes Jun 03 '18 at 02:45
  • You for sure cannot do it for normal link, but if you i.e. open window from javascript, it might be possible to do something. – Petr Averyanov Jun 03 '18 at 16:14

1 Answers1

1

There is unfortunately no parameter to put into a link pointing to another website that would make a browser scroll the page to a given position after opening it.

Programmatically it cannot be done either as a website doesn't have any access to websites on other domains. (Even loading the external resource into an iframe or popup wouldn't help as Same-origin policy still prevents you to make any changes to it. See the comments under this answer to a similar question.)

tom
  • 2,137
  • 2
  • 27
  • 51
  • See [Scrolling an iframe with JavaScript?](https://stackoverflow.com/questions/1192228/scrolling-an-iframe-with-javascript). – georgeawg Jun 03 '18 at 03:35