简体   繁体   English

在新标签iframe角度和非角度应用中打开相同的网址

[英]Open the same url in new tab iframe angular and non angular app

I am very new to the angular and front end technologies. 我对角度和前端技术非常陌生。 I have an existing application which is very big. 我有一个很大的现有应用程序。 We are transforming it into the angular. 我们正在将其转换为角度。 So we made our angular as a main app and load the old app inside the iFrame. 因此,我们将Angle作为主要应用程序并将旧应用程序加载到iFrame中。

My angular app run when user hits www.xyz.com/dashboard This URL never changes in my browser, and old app content gets loaded inside the iFrame. 当用户点击www.xyz.com/dashboard时,我的有角度的应用程序就会运行。此URL在我的浏览器中从未更改,并且旧的应用程序内容已加载到iFrame中。 When user navigates from one page to other page iFrame source URL changes. 当用户从一页导航到另一页时,iFrame源URL会更改。

Now When user right click on any of the link within the iFrame and click to open in new tab, application page open in new tab, but it loads the old url like www.xyz.com/oldApp/clicked/page/ 现在,当用户右键单击iFrame中的任何链接,然后单击以在新标签页中打开时,应用程序页面将在新标签页中打开,但是它会加载旧网址,例如www.xyz.com/oldApp/clicked/page/

What I want to do is if user opens any link within iFreame(old app) it should open the page in new tab but with the current URL(www.xyz.com/dashboard) in browser. 我想做的是,如果用户在iFreame(旧应用程序)中打开任何链接,则应在新标签页中打开页面,但在浏览器中使用当前URL(www.xyz.com/dashboard)。

I got the answer. 我得到了答案。 It checks the URL is loading inside the iframe or parent window. 它检查URL是否正在iframe或父窗口中加载。 If it is a parent window then redirects it to angular url. 如果它是父窗口,则将其重定向到角度URL。 And angular URL know which page needs to be loaded in frame and this page is lastVistitedPage 角度URL知道需要在框架中加载哪个页面,而该页面是lastVistitedPage

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();
}

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM