function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sadik Shaik 3Sadik Shaik 3 

I got this popup that when you scroll down to the bottom of the page and click the close button, it scrolls the user to the top of the page.

Close link code in java script:
<a href=\"#\" onclick=\"box.hide();\">Close</a>


I would like the user to not get redirected to the top of the page after close. how do we do that?
Thanks in advance
Best Answer chosen by Sadik Shaik 3
Khan AnasKhan Anas (Salesforce Developers) 
Hi Sadik,

Greetings to you!

The jump-to-top was just the default browser behavior. You need to call event.preventDefault() in your onClick handler.

Or you can use something like this.

<a href="#" onClick={event => {event.preventDefault(); box.hide();}}>Close</a>

Refer below links for more information:

https://github.com/reactjs/react-modal/issues/117#issuecomment-333409035

https://stackoverflow.com/questions/265478/preventdefault-on-an-a-tag

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas

All Answers

Khan AnasKhan Anas (Salesforce Developers) 
Hi Sadik,

Greetings to you!

The jump-to-top was just the default browser behavior. You need to call event.preventDefault() in your onClick handler.

Or you can use something like this.

<a href="#" onClick={event => {event.preventDefault(); box.hide();}}>Close</a>

Refer below links for more information:

https://github.com/reactjs/react-modal/issues/117#issuecomment-333409035

https://stackoverflow.com/questions/265478/preventdefault-on-an-a-tag

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
This was selected as the best answer
Sadik Shaik 3Sadik Shaik 3
That is not workng but i have tried with the below code that is working as expected.
<a href=\"#bottom\" onclick=\"box.hide();\">Close</a>

Thanks for your involvement to reslove this issue.