0

When i put my iframe it says the following error,

Refused to display 'my url' in a frame because it set 'X-Frame-Options' to 'DENY, DENY'.I am using this iframe for the first time.


 <iframe src="myurl"></iframe>

Can anyone please help me about the situation.

My ctrl,

$scope.trustSrc = function(src) {
  return $sce.trustAsResourceUrl(src);
}

My html,

<iframe ng-src="{{trustSrc(https://www.w3schools.com)}}"></iframe>
Vik David
  • 3,640
  • 4
  • 21
  • 29
Duster
  • 99
  • 3
  • 9

1 Answers1

2

You can have a function defined and pass the url to it,

$scope.trustSrc = function(src) {
        return $sce.trustAsResourceUrl(src);
}

and in HTML

<iframe ng-src="{{trustSrc(myurl)}}"></iframe>

Note: You need to inject '$sce' as a parameter to your controller.

DEMO

var app = angular.module('myApp',[]);
app.controller('myCtrl',function($scope,$sce){
$scope.trustSrc = function(src) {
  return $sce.trustAsResourceUrl(src);
}
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="myApp">
<div ng-controller="myCtrl">
<iframe   height="100%" width="100%" ng-src="{{trustSrc('http://www.espncricinfo.com/')}}"></iframe>
</div>
</body>
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
  • Hi,sajeetharan.Its not workin I edited my code,can u pls check. – Duster Aug 09 '17 at 06:18
  • check the demo attached or this http://plnkr.co/edit/YlWzMyMZcwcLXHLsIQcZ?p=preview – Sajeetharan Aug 09 '17 at 06:26
  • ,its working for me with your example but when I put my url,it says error Refused to display 'myurl' in a frame because it set 'X-Frame-Options' to 'DENY, DENY'. – Duster Aug 09 '17 at 09:35