简体   繁体   English

MVC JavaScript的window.open添加到url

[英]MVC JavaScript's window.open adds to url

I am using MVC3 and jQuery. 我正在使用MVC3和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. 我正在使用click事件(而不是链接)因为我有一些自定义逻辑,它会将值添加到它正在调用的外部站点的查询字符串中。

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. JavaScript window.open函数正在打开一个新窗口,但它预先挂起了原始网站的URL到外部网站URL的开头。

Here is the jQuery code I am using: 这是我正在使用的jQuery代码:

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

The new window opens with the URL of: 将打开新窗口,其URL为:

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

Any ideas? 有任何想法吗?

I have tried using _blank as the name. 我尝试过使用_blank作为名称。

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. 使用错误的斜杠,它将被解释为相对URL。

you url is incorrect. 你的网址不正确。 You need to use forward slashes not backslashes. 你需要使用正斜杠而不是反斜杠。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM