I'm writing a simple angular app, and I want to make a browser like thing: a input box user can type url, an iframe to display content of the url, a button which user can press to go back.
I use $sce to ng-src in iframe to accept any website user input. But cannot implement history back function because of CORS problem.
Is there any possibility to achieve it? Thanks
JS
$scope.testurl = $sce.trustAsResourceUrl("http://www.baidu.com");
$scope.backPage = function () {
var ifr = document.getElementById("myIframe");
ifr.contentWindow.history.back();
}
HTML
<ion-view view-title="Account">
<ion-content>
<div ng-click="backPage()">BACK</div>
<iframe id="myIframe" style="height:500px;width:100vw" ng-src="{{testurl}}"></iframe>
</ion-content>
</ion-view>
Error
Error: Blocked a frame with origin "http://localhost:8101" from accessing a cross-origin frame.
at Error (native)
at Scope.$scope.backPage (http://localhost:8101/js/controllers.js:32:24)
at fn (eval at compile (http://localhost:8101/lib/ionic/js/ionic.bundle.js:27638:15), <anonymous>:4:215)
at http://localhost:8101/lib/ionic/js/ionic.bundle.js:65427:9
at Scope.$eval (http://localhost:8101/lib/ionic/js/ionic.bundle.js:30395:28)
at Scope.$apply (http://localhost:8101/lib/ionic/js/ionic.bundle.js:30495:25)
at HTMLDivElement.<anonymous> (http://localhost:8101/lib/ionic/js/ionic.bundle.js:65426:13)
at defaultHandlerWrapper (http://localhost:8101/lib/ionic/js/ionic.bundle.js:16787:11)
at HTMLDivElement.eventHandler (http://localhost:8101/lib/ionic/js/ionic.bundle.js:16775:9)
at triggerMouseEvent (http://localhost:8101/lib/ionic/js/ionic.bundle.js:2953:7)