javascript - 在新标签 iframe 角度和非角度应用程序中打开相同的 url
问题描述
我对角度和前端技术非常陌生。我有一个非常大的现有应用程序。我们正在将其转换为角度。因此,我们将 Angular 作为主应用程序,并将旧应用程序加载到 iFrame 中。
当用户点击 www.xyz.com/dashboard 时,我的 Angular 应用程序运行此 URL 在我的浏览器中永远不会更改,并且旧的应用程序内容会加载到 iFrame 中。当用户从一个页面导航到另一个页面时,iFrame 源 URL 会发生变化。
现在,当用户右键单击 iFrame 中的任何链接并单击以在新选项卡中打开时,应用程序页面会在新选项卡中打开,但它会加载旧网址,例如 www.xyz.com/oldApp/clicked/page/
我想要做的是,如果用户在 iFreame(旧应用程序)中打开任何链接,它应该在新选项卡中打开页面,但在浏览器中使用当前 URL(www.xyz.com/dashboard)。
解决方案
我得到了答案。它检查 URL 是否在 iframe 或父窗口中加载。如果它是父窗口,则将其重定向到角度 url。并且角度 URL 知道需要在框架中加载哪个页面,并且该页面是 lastVisitedPage
var iFrameDetection = (window === window.parent) ? false : true;
if(!iFrameDetection) {
setCookie("lastVistitedPage", location, "3");
var newUrl = window.location.origin;
newUrl = newUrl.replace("8080", "4200");
window.location.href = newUrl + "/dashboard";
}else {
$(window).on( 'hashchange', function( e ) {
postMessageForDocTitle();
});
postMessageForDocTitle();
}
}
推荐阅读
- azure - Terraform - 如何将环境变量传递给 terraform 中的子模块
- swift - swift中的线程1信号sigabrt
- r - R 用于解决线性规划营销问题
- python - 使用 pip install leveldb 时出现错误
- react-native - Reactnavigation - 不要按返回按钮返回登录屏幕
- typescript - 将本地 JS 模块导入 TS 文件的最简单方法是什么?
- typescript - 如何修复打字稿中的“不能将命名空间用作类型 ts(2709)”?
- python - 使用 Tkinter 移动图像
- .net-core - Protobuf-net 缺少依赖 System.Private.ServiceModel
- php - 对 PHP REST API 的 POST 请求仅适用于 Postman