MVC JavaScript 的 window.open 添加到 url

发布于 2024-12-05 05:58:31 字数 523 浏览 1 评论 0原文

我正在使用 MVC3 和 jQuery。我正在尝试打开外部网站。我使用点击事件(而不是链接),因为我有一些自定义逻辑,可以将值添加到它正在调用的外部站点的查询字符串中。

JavaScript window.open 函数正在打开一个新窗口,但它将原始网站的 URL 置于外部网站 URL 的开头。

这是我正在使用的 jQuery 代码:

$(function () {
        $("#btnTransfer").click(function () {
            //custom logic
            window.open('http:\\www.google.com');
        });

新窗口打开,URL 为:

http://localhost:28761/www.google.com

有什么想法吗?

我尝试使用 _blank 作为名称。

I am using MVC3 and jQuery. I am trying to open an external website. I am using the click event (and not a link) because I have some custom logic that will add values to a query string of the external site it is calling.

The JavaScript window.open function is opening a new window, however it is pre-pending the original website's URL to the begining of the external website's URL.

Here is the jQuery code I am using:

$(function () {
        $("#btnTransfer").click(function () {
            //custom logic
            window.open('http:\\www.google.com');
        });

The new window opens with the URL of:

http://localhost:28761/www.google.com

Any ideas?

I have tried using _blank as the name.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苍白女子 2024-12-12 05:58:31

你的斜杠是向后的:

window.open('http:\\www.google.com');

应该

window.open('http://www.google.com');

使用错误的斜杠,它会被解释为相对网址。

Your slashes are backwards:

window.open('http:\\www.google.com');

should be

window.open('http://www.google.com');

with the wrong slashes it would be interpreted as a relative url.

£噩梦荏苒 2024-12-12 05:58:31

你的网址不正确。您需要使用正斜杠而不是反斜杠。

window.open('http://www.google.com');

you url is incorrect. You need to use forward slashes not backslashes.

window.open('http://www.google.com');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文