简体   繁体   中英

Redirect outside the current domain using javascript

I want to redirect to another website outside of my domain, such as this:

<img src="http://url.to.file.which/not.exist" onerror=window.open("www.google.com","xss",'height=500,width=500');>

I put the above code into a simple html file. However, it keeps appending the file path before "www.google.com" when the pop up show up. Is there a way to remove?

您在域之前错过了协议 http(s):// -

<img src="http://url.to.file.which/not.exist" onerror=window.open("https://www.google.com","xss",'height=500,width=500');>

使用完整的URL: window.open("http://www.google.com"...

To use an absolute url you need to specify the protocol. In your case you want http:// .

So just change www.google.com to 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