使用Javascript在新窗口中打开URL [英] Open URL in new window with Javascript

查看:100
本文介绍了使用Javascript在新窗口中打开URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个分享按钮来分享当前页面。我想获取当前页面URL并在新窗口中打开它。我有当前的URL部分工作,但似乎无法使下一部分工作。

I'm making a "share button" to share the current page. I would like to take the current page URL and open it in a new window. I have the current URL part working, but can't seem to get the next part working.

我正在努力学习语法。我想将新窗口大小指定为 width = 520,height = 570

I'm struggling with the syntax. I would like to specify the new window size to width=520, height=570.

类似于:

<a target="_blank" href="https://www.linkedin.com/cws/share?mini=true&amp;url=[sub]" onclick="this.href = this.href.replace('[sub]',window.location)">LinkedIn</a>

任何想法?

推荐答案

使用 window.open()

<a onclick="window.open(document.URL, '_blank', 'location=yes,height=570,width=520,scrollbars=yes,status=yes');">
  Share Page
</a>

这将创建一个标题为 Share Page 的链接在新窗口中打开当前URL,高度为570,宽度为520.

This will create a link titled Share Page which opens the current url in a new window with a height of 570 and width of 520.

这篇关于使用Javascript在新窗口中打开URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆