Sergio
Sergio

Reputation: 1423

Why page gets blank with "[Object]" after javascript:window.open?

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!

Upvotes: 3

Views: 3605

Answers (2)

Hariprasad
Hariprasad

Reputation: 3640

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

Upvotes: 0

epascarello
epascarello

Reputation: 207517

Because 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.

Upvotes: 6

Related Questions