javascript 使用javascript重定向到当前域之外

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7172732/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 23:11:28  来源:igfitidea点击:

Redirect outside the current domain using javascript

javascriptxss

提问by Amumu

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?

我把上面的代码放到一个简单的html文件中。但是,当弹出窗口出现时,它会在“www.google.com”之前附加文件路径。有办法去除吗?

回答by CONvid19

You missed the protocol- http(s)://- before the domain

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

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

回答by CyberDude

Use the full URL: window.open("http://www.google.com"...

使用完整网址: window.open("http://www.google.com"...

回答by Paul

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

要使用绝对 url,您需要指定协议。在你的情况下,你想要http://.

So just change www.google.comto http://www.google.com

所以只需更改www.google.comhttp://www.google.com