Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maintain scroll position in Javascript window.open()

Tags:

javascript

How do I maintain the scroll position of the parent page when I open new window using window.open()? The parent page returns to the top of the page.

Here is my current code:

<a href="#" onclick="javascript: window.open('myPage.aspx');">
   Open New Window
</a>
like image 924
Michael Kniskern Avatar asked Dec 30 '22 07:12

Michael Kniskern


1 Answers

<a href="#" onclick="window.open('myPage.aspx');return false;">Open New Window</a>
  • javascript: is not required in event attributes.
  • You were not returning false from the event handler, so the link was being following, it was equivilent to <a href="#">Scroll to top</a>.
like image 165
Grant Wagner Avatar answered Jan 13 '23 19:01

Grant Wagner