$sce.trustAsResourceUrl is not working

2019-09-05 02:42发布

问题:

I am working with iframe in my project just tried to open url inside my app through iframe , but its not working at my end , please have a look and provide your valuable suggestion.I will be very thank full to you .

Here is my controller code :-

app.controller('IframeCtrl', function($http, $scope, $ionicPopup, $state,
		$ionicLoading, LocalStorage, $sce) {

	$scope.customUrl = $sce.trustAsResourceUrl('http://www.magentomobileshop.com/demo/payu/index/payu?orderid='
			+ LocalStorage.getData("orderid"));

	window.checkIframeUrl = function(curentUrl) {
		alert(curentUrl);
	};
	

});

My iframe.hml :-

<ion-view view-title="PayU Money"> <ion-nav-bar
	class="bar-positive" align-title="center"> </ion-nav-bar> <iframe
	src="{{customUrl}}" src="http://www.google.com"
	onLoad="checkIframeUrl(src);" scrolling="none" frameborder="0"
	height="600px" width="100%"></iframe> <ion-content> </ion-content> </ion-view>
I even try this link :- http://jsfiddle.net/W4WyL/4/

here is what i try now as :-

My conroller :-

 function($http, $scope, $sce) {

 
 var url="http://www.magentomobileshop.com/demo/payu/index/payu?orderid=100000030"
 
    $http.get($sce.trustAsResourceUrl(url)).success(function(data) {
     $scope.myData  = data;
     
    });
 
}

My new Html :-

 <div><iframe
	ng-src={{myData}} frameborder="0"
	height="600px" width="100%"></iframe> </div>
    </div>

Okay, i think this might be the issue that payU is a secured Url so this might not be getting open on iFrame but is there any way i can track url in window.open(), so that i can close the webview when i will be on that tracked Url.

Thanks

回答1:

I don't know if iframe is supported by angular logic. Anyways, instead of the doubled "src" attribute, write

ng-src="{{securedUrl}}"

Also, it would be nice to put a validity check on the

LocalStorage.getData("orderid")

value.



回答2:

Ah wait. I didn't notice you are inflating that value as a query param. I don't think it could work in any way. You are just filling an address, and whitelisting a link, you are not getting the data.

You probably could use

$http({
    url : $sce.trustAsResourceUrl( yourURL ),
    method : "GET"
}).then(
   function(data){
      $scope.myData = data;
   },
   function(error){
      // manage error
   }
);