[英]javascript go to url with unicode characters
I have an array with some urls like these: 我有一个数组,其中包含一些这样的网址:
[
"path/to/url1",
"path/to/url2",
"path/url/unicóde.txt"
]
I'm using angular, with ng-repeat
I created a clickable list that perform a redirect to desired url, but, when I clicked unicode url, the browser cant find it. 我正在使用angular,使用ng-repeat
我创建了一个可点击列表,可以执行重定向到所需的URL,但是,当我单击unicode url时,浏览器无法找到它。
I try with encodeURI("path/url/unicóde")
, but it retrieves this: path/url/unic%C3%B3de.txt
which is not found. 我尝试使用encodeURI("path/url/unicóde")
,但它检索到: encodeURI("path/url/unicóde")
path/url/unic%C3%B3de.txt
。 Instead, when I accessing manually to: path/url/unicóde.txt
(this is in an ftp, so, I go folder by folder until arrive to the file) the url in the browser now says: path/url/unic%F3de.txt
, which is different to value that gave me encodeURI( )
. 相反,当我手动访问: path/url/unicóde.txt
(这是在ftp中,所以,我按文件夹逐个文件夹,直到到达文件)浏览器中的url现在说: path/url/unic%F3de.txt
,这与给我encodeURI( )
值不同。
How then I can clic to this list item and to be redirected to desired unicode url? 那我怎么可以clic到这个列表项并被重定向到所需的unicode网址?
Here the code: html: 这里的代码:html:
<md-list-item ng-repeat="found in foundFiles">
<h3>{{ found.name }}</h3>
<p ng-click="openFtpLink(found.url)">{{ found.url}}</p>
</md-list-item>
javascript: JavaScript的:
$scope.foundFiles = [...]
$scope.openFtpLink = function (ftpLink) {
var spawn = require('child_process').spawn;
spawn('cmd.exe', ['/c', 'start', '', ftpLink]);
};
This is an app build with electron + angular, what I want here is that when user clicks the item, open his default browser and redirect it to url 这是一个带有电子+角度的应用程序构建,我想要的是当用户点击该项目时,打开他的默认浏览器并将其重定向到网址
Use JavaScript escape()
Function. 使用JavaScript escape()
函数。 It gives you desired output. 它为您提供所需的输出。
alert(escape("path/url/unicóde.txt"));
Note : The escape()
function was deprecated in JavaScript version 1.5. 注意:在JavaScript 1.5版中不推荐使用escape()
函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.