最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

asp.net - Why page gets blank with "[Object]" after javascript:window.open? - Stack Overflow

programmeradmin1浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 6

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.

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

发布评论

评论列表(0)

  1. 暂无评论