i’m using a windows.open popup and when i click it the page automatically goes up, how do i prevent this? i tried ‘top:auto’ it doesnt work here is my code
function openPopup() { var divText = document.getElementById("pass").outerHTML; var myWindow = window.open('', '', 'width=500,height=200,top=100'); var doc = myWindow.document; doc.open(); doc.write(divText); doc.close(); }
<a href="#" onclick="openPopup()">Read More</a>
The browser is executing your onClick handler, then continuing with the default behavior — clicking the link, which causes the browser to scroll to the
#anchor. (The location bar will also get a # at the end to reflect this.) You want your onClick handler to suppress the click event, so have itreturn false: