Angularjs 如何在iframe之外操纵历史

Angularjs 如何在iframe之外操纵历史,angularjs,html,iframe,Angularjs,Html,Iframe,我正在编写一个简单的angular应用程序,我想做一个类似浏览器的东西:一个输入框用户可以键入url,一个iframe显示url的内容,一个按钮用户可以按下返回 我在iframe中使用$sce to ng src来接受任何网站用户输入。但由于CORS问题,无法实现历史回溯功能 有可能实现吗?谢谢 JS HTML 返回 错误 错误:阻止了具有原点的帧”http://localhost:8101“从访问交叉原点帧。 错误(本机) 在Scope.$Scope.backPage(http://loc

我正在编写一个简单的angular应用程序,我想做一个类似浏览器的东西:一个输入框用户可以键入url,一个iframe显示url的内容,一个按钮用户可以按下返回

我在iframe中使用$sce to ng src来接受任何网站用户输入。但由于CORS问题,无法实现历史回溯功能

有可能实现吗?谢谢

JS

HTML


返回
错误

错误:阻止了具有原点的帧”http://localhost:8101“从访问交叉原点帧。
错误(本机)
在Scope.$Scope.backPage(http://localhost:8101/js/controllers.js:32:24)
fn时(编译时评估)(http://localhost:8101/lib/ionic/js/ionic.bundle.js:27638:15), :4:215)
在http://localhost:8101/lib/ionic/js/ionic.bundle.js:65427:9
在范围内。$eval(http://localhost:8101/lib/ionic/js/ionic.bundle.js:30395:28)
在范围内。$apply(http://localhost:8101/lib/ionic/js/ionic.bundle.js:30495:25)
在HTMLDEVELENT。(http://localhost:8101/lib/ionic/js/ionic.bundle.js:65426:13)
在defaultHandlerWrapper(http://localhost:8101/lib/ionic/js/ionic.bundle.js:16787:11)
在htmldevelment.eventHandler(http://localhost:8101/lib/ionic/js/ionic.bundle.js:16775:9)
在三角洲事件中(http://localhost:8101/lib/ionic/js/ionic.bundle.js:2953:7)
用于URL,这些URL不仅可以安全地作为链接跟随,而且其内容也可以安全地包含在应用程序中。示例包括非IMG标记的ng include、src/ngSrc绑定(例如IFRAME、OBJECT等)

请注意,$sce.RESOURCE_URL比$sce.URL更能说明URL,因此需要$sce.RESOURCE_URL信任值的上下文可以在需要$sce.URL信任值的任何地方使用


使用
窗口。历史记录
对象

// For the current window
window.history.back();     
window.history.forward();

// For an iframe's window
iframe.contentWindow.history.back(); 
iframe.contentWindow.history.forward();


这里有可能出现以下问题,包括讨论和一些相关问题:
<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: 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)
app.config(function($sceDelegateProvider) {
 $sceDelegateProvider.resourceUrlWhitelist([
    // Allow same origin resource loads.
    'self',
    // Allow loading from our assets domain.  Notice the difference between * and **.
    'http://www.baidu.com'
  ]);

  // The blacklist overrides the whitelist so the open redirect here is blocked.
  $sceDelegateProvider.resourceUrlBlacklist([
    'http://myapp.example.com/clickThru**'
  ]);
});
// For the current window
window.history.back();     
window.history.forward();

// For an iframe's window
iframe.contentWindow.history.back(); 
iframe.contentWindow.history.forward();
iframe.contentWindow.history.go(-1); // back
iframe.contentWindow.history.go(1);  // forward