简体   繁体   中英

Javascript Pop-Up WIndow Open Function

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

<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.

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

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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