Javascript弹出窗口打开功能

时间:2021-08-30 07:13:32

I am using the following JS function to open a pop-up window to display another website:

我使用以下JS函数打开一个弹出窗口来显示另一个网站:

<script language="javascript" type="text/javascript">
function link()
{
   window.open("www.google.com")
}

onClick="Link()"

The URL in the above example is just for testing. I actually intend on replacing the URL with a text value from a listbox, which is in the form of a URL. Anyway, when ever I start the debugger in Visual Studio, and execute the onClick, the pop-up window opens and gives me a page stating that there is a server error. Specifically, Server error in '/' application... resource cannot be found. Also, I notice that my URL is placed as follows: http://localhost:49456/www.google.com. I thought this function would give me a pop-up window with Google as the website. Is this a Visual Studio debugger issue, is my code wrong, or am I using the code in the wrong context? Any suggestions would be greatly appreciated.

上例中的URL仅用于测试。我实际上打算用列表框中的文本值替换URL,该列表框是URL的形式。无论如何,当我在Visual Studio中启动调试器并执行onClick时,弹出窗口会打开并给出一个页面,指出存在服务器错误。特别是,无法找到“/”应用程序...资源中的服务器错误。另外,我注意到我的URL放置如下:http:// localhost:49456 / www.google.com。我认为这个功能会给我一个弹出窗口,谷歌作为网站。这是一个Visual Studio调试器问题,我的代码是错误的,还是我在错误的上下文中使用代码?任何建议将不胜感激。

2 个解决方案

#1


you need to specify http:// in the url eg

你需要在URL中指定http://例如

window.open("http://google.com");

without that protocol specified, the browser will think the URL is relative to the current document.

如果未指定该协议,浏览器将认为URL相对于当前文档。

#2


Add http:// to your domain, i.e. http://www.google.com.

将http://添加到您的域名,即http://www.google.com。

#1


you need to specify http:// in the url eg

你需要在URL中指定http://例如

window.open("http://google.com");

without that protocol specified, the browser will think the URL is relative to the current document.

如果未指定该协议,浏览器将认为URL相对于当前文档。

#2


Add http:// to your domain, i.e. http://www.google.com.

将http://添加到您的域名,即http://www.google.com。