I've put a link on one page that opens a new window. the markup it's:
Click <a href="javascript:window.open('../SomePage.aspx', 'mynewwin', 'width=880,height=600,toolbar=0,scrollbars=1,resizable=1');" >HERE</a>.
It happens that when I click the link, the new page shows perfect, but the old one gets blank and only "[Object]" it's writen on it. It should stay as it was.
It's weird!
I've put a link on one page that opens a new window. the markup it's:
Click <a href="javascript:window.open('../SomePage.aspx', 'mynewwin', 'width=880,height=600,toolbar=0,scrollbars=1,resizable=1');" >HERE</a>.
It happens that when I click the link, the new page shows perfect, but the old one gets blank and only "[Object]" it's writen on it. It should stay as it was.
It's weird!
Share Improve this question asked Dec 17, 2013 at 19:26 SergioSergio 1,4232 gold badges14 silver badges30 bronze badges 3- 4 Try adding "void(0);" to the end of the href, i.e. href="javascript:.....;void(0);" – murdock Commented Dec 17, 2013 at 19:34
- @murdock: You're right. that works. But not an answer. Thanks. – Sergio Commented Dec 18, 2013 at 16:15
- @murdock You should write that as an answer. – Akash KC Commented Aug 1, 2019 at 14:42
2 Answers
Reset to default 6Because you are not cancelling the click action.
Click <a href="javascript:window.open('../SomePage.aspx', 'mynewwin', 'width=880,height=600,toolbar=0,scrollbars=1,resizable=1');return false;" >HERE</a>
ideally you would not use the href to open the window.
<a target="_blank" href="../SomePage.aspx" onclick="window.open(this.href, 'mynewwin', 'width=880,height=600,toolbar=0,scrollbars=1,resizable=1');return false;" >
even better would be to attach the link event in an unobtrusive manner.
Try this:
<script>
function myFunc()
{
window.open('../SomePage.aspx', 'mynewwin','width=880,height=600,toolbar=0,scrollbars=1,resizable=1');
}
</script>
<body>
Click <a href="#" onclick="return myFunc();">HERE</a>
</body>
JSFIDDLE