Search code examples
jqueryangularjsnode.jsreactjsanchor-scroll

Force scroll to specific top value on external website


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.


Solution

  • 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.)