<iframe id="myFrame" ng-src="{{url}}" width="100%" height="100%" seamless frameborder="0" ></iframe>
打開不同域的內容時報下面的錯誤:
Blocked loading resource from url not allowed by $sceDelegate policy
解決方案:
代碼如下:
app.config(function($sceDelegateProvider) {
$sceDelegateProvider.resourceUrlWhitelist([
// Allow same origin resource loads.
'self',
// Allow loading from our assets domain. Notice the difference between * and **.
'http://media.w3.org/**']);
});
很簡單的方法就解決了angularjs跨域使用iframe的問題,希望大家能夠喜歡