Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
248 views
in Technique[技术] by (71.8m points)

javascript - AngularJS在扩展页面中将URL更改为“unsafe:”(AngularJS changes URLs to “unsafe:” in extension page)

I am trying to use Angular with a list of apps, and each one is a link to see an app in more detail ( apps/app.id ):(我正在尝试将Angular与应用列表一起使用,每个应用都是一个链接,可以更详细地查看应用( apps/app.id ):)

<a id="{{app.id}}" href="apps/{{app.id}}" >{{app.name}}</a> Every time I click on one of these links, Chrome shows the URL as(每次我点击其中一个链接时,Chrome都会将网址显示为) unsafe:chrome-extension://kpbipnfncdpgejhmdneaagc.../apps/app.id Where does the unsafe: come from?(unsafe:来自哪里?)   ask by ebi translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to explicitly add URL protocols to Angular's whitelist using a regular expression.(您需要使用正则表达式向Angular的白名单中明确添加URL协议。)

Only http , https , ftp and mailto are enabled by default.(默认情况下,仅启用httphttpsftpmailto 。) Angular will prefix a non-whitelisted URL with unsafe: when using a protocol such as chrome-extension: .(Angular将使用unsafe:的非白名单URL作为前缀unsafe:当使用chrome-extension:等协议时chrome-extension: 。) A good place to whitelist the chrome-extension: protocol would be in your module's config block:(将chrome-extension:列入白名单的好地方chrome-extension:协议将在您的模块的配置块中:) var app = angular.module( 'myApp', [] ) .config( [ '$compileProvider', function( $compileProvider ) { $compileProvider.aHrefSanitizationWhitelist(/^s*(https?|ftp|mailto|chrome-extension):/); // Angular before v1.2 uses $compileProvider.urlSanitizationWhitelist(...) } ]); The same procedure also applies when you need to use protocols such as file: and tel: .(当您需要使用诸如file:tel:协议时,同样的过程也适用。) Please see the AngularJS $compileProvider API documentation for more info.(有关详细信息,请参阅AngularJS $ compileProvider API文档 。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...