Basic Javascript question: How to open a new window?

前端 未结 4 1326
暗喜
暗喜 2021-01-28 13:39

How do I open a new window in javascript properly?

I\'ve tried:



        
4条回答
  •  佛祖请我去吃肉
    2021-01-28 14:40

    By putting the script in the href property, the link will follow the string representation of the return value of the script.

    The most backwards compatible way is to put the url and target in the link as regular attributes, and use the onclick event to open a window instead of following the link. By returning false from the event you prevent the link from being followed:

    New Window
    

    If Javascript is disabled in the browser, it will follow the link instead and open it in a new window.

    Use the target _blank to open a new window.

提交回复
热议问题