Keroro Chan
Keroro Chan

Reputation: 99

html go to the specific element of another page if the element is not shown yet?

I used anchor to go to the specific element of another page from the current page. But, The specific element of the page which I want to go is not shown yet because it is controlled by javascript so that the page can be kept short. The element is shown when the user clicks the button. So, are they any methods that realize my following idea?

If the specific element have be shown already, just use normal anchor. else click the button until the specific element is shown, and use anchor to go to there.

Upvotes: 0

Views: 86

Answers (2)

sideroxylon
sideroxylon

Reputation: 4416

Add a query string to the URL instead of an anchor:

http://www.example.com/?q=1

Then, on the target page, get the query string and find the value of q. Then, if the value is the one you want, click the button to reveal the hidden element:

$('#button').click()

And finally, scroll to the element:

$('html, body').animate({ scrollTop: $('#hidden_element').offset().top },{ duration: 1000});

Upvotes: 1

Zamboney
Zamboney

Reputation: 2010

you can call location.hrefand the target you wish to go to. you can do it anywhere in your code and after you append the target to the element

if the target is already in the page then just add it to the url as a hash

Upvotes: 0

Related Questions