【问题标题】:window.open vs window.location.hrefwindow.open 与 window.location.href
【发布时间】:2019-08-13 00:20:48
【问题描述】:

如何决定是用window.open 还是window.location.href 打开本地网页窗口?

【问题讨论】:

标签: javascript html


【解决方案1】:

简单地说,

window.open() 将在括号内为您传递的 URL 打开一个新窗口。

window.location.href 会将您重定向到在同一窗口中传递的 URL。

【讨论】:

  • 我的意思是在本地网页中使用 jQuery 或 javascript。你能有个好主意吗?谢谢。
  • 据我所知,我认为最好在项目文件夹中的单独文件中使用 javascript。但无论如何,这取决于你的口味:)
【解决方案2】:

如果 window.opener == null

//由window.location.href打开

其他

//通过window.open打开

【讨论】:

    猜你喜欢
    • 2011-06-16
    • 2013-09-09
    • 2011-10-28
    • 1970-01-01
    • 1970-01-01
    • 2010-12-12
    • 2012-04-29
    • 1970-01-01
    相关资源
    最近更新 更多