javascript - How to change iframe src use angularjs -


<iframe src="{{url}}" width="300" height="600">                 <p>your browser not support iframes.</p>             </iframe> 

how change iframe src

you need $sce.trustasresourceurl or won't open website inside iframe:

jsfiddle

html:

<div ng-app="myapp" ng-controller="dummy">     <button ng-click="changeit()">change it</button>     <iframe ng-src="{{url}}" width="300" height="600"></iframe> </div> 

js:

angular.module('myapp', [])     .controller('dummy', ['$scope', '$sce', function ($scope, $sce) {      $scope.url = $sce.trustasresourceurl('https://www.angularjs.org');      $scope.changeit = function () {         $scope.url = $sce.trustasresourceurl('https://docs.angularjs.org/tutorial');     } }]); 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -