locked
Need to call Project A javascript function in Project B RRS feed

  • Question

  • User-234441352 posted

    Hi,

    We have developed two applications.

    (Project A)  One is very old application and developed in Asp.Net MVC 4 (.Net Framework 4).

    (Project B) Now we have developed a small project developed in Asp.Net MVC 5/Web API2 using .Net Framework 4.7.2.

    The purpose for creating a second project is purely related to the usage of Paypal Checkout API V2 ( Prerequisites .NET 4.6.1 or later).

    We want to access project B in project A and I am using it through iframe by using it in Project A.

    Now What do I need to use the project A javascript function in Project B and Project A has iframe and load project B partial view.

    Now when I am trying to use following 

    Project A
    
    $('#frmProjectADiv').html('<iframe id="lProjNow" src="' + window.ProjectBAPIPath + '" />');
    
    Project B
    
    
    window.parent.document
    
    // Or 
    
    parent.abc() 

    // Or

    window.top.document.

    Both above approach are giving me errors and not allowing me to run a function in Project A.

    Saturday, November 21, 2020 11:05 AM

Answers

  • User475983607 posted

    Both above approach are giving me errors and not allowing me to run a function in Project A.

    If I understand the approach correctly, browser security will not allow Program B to execute JavaScript functions in Program A.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, November 21, 2020 3:05 PM
  • User-474980206 posted

    Browsers have increased iframe security. Your site will need to have a common domain. Here is an article

    https://javascript.info/cross-window-communication

    Note: why didn’t you just upgrade the old project to a supported version of 4.*?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, November 21, 2020 3:49 PM
  • User-474980206 posted

    If you upgrade I’d problem go 4.8 and mvc 5 (not to be confused with .net core). 4.8 has long term support. If it’s a website application I’d upgrade to a project based, this is tedious but only a days work. Once the current site is 4.8 you can add mvc to the project.

    if your old site is mvc 3, then updating to mvc 4/5 will run into a couple razor syntax changes. just be sure to enable razor recompile and you will catch.

    the other issue is encryption. The default key sizes have been changed. If you need compatible with old data, you will need to override the settings.

    I upgraded a 4.0 sites with dozens of libraries and to 4.8 and it was just tedious, not hard or long. You start with the highest level first. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, November 21, 2020 8:47 PM

All replies

  • User475983607 posted

    Both above approach are giving me errors and not allowing me to run a function in Project A.

    If I understand the approach correctly, browser security will not allow Program B to execute JavaScript functions in Program A.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, November 21, 2020 3:05 PM
  • User-474980206 posted

    Browsers have increased iframe security. Your site will need to have a common domain. Here is an article

    https://javascript.info/cross-window-communication

    Note: why didn’t you just upgrade the old project to a supported version of 4.*?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, November 21, 2020 3:49 PM
  • User-234441352 posted

    Thank you mgebhard and Bruce.  I start to look both options Bruce and share the update. 

    The error describe same as you have mentioned.

    Yes it's a good to try to upgrade. Net framework 4.6.2. 

    But what about MVC 4 ?

    Can .Net framework and MVC version cause any compatibility  issue? 

    Saturday, November 21, 2020 7:09 PM
  • User-474980206 posted

    If you upgrade I’d problem go 4.8 and mvc 5 (not to be confused with .net core). 4.8 has long term support. If it’s a website application I’d upgrade to a project based, this is tedious but only a days work. Once the current site is 4.8 you can add mvc to the project.

    if your old site is mvc 3, then updating to mvc 4/5 will run into a couple razor syntax changes. just be sure to enable razor recompile and you will catch.

    the other issue is encryption. The default key sizes have been changed. If you need compatible with old data, you will need to override the settings.

    I upgraded a 4.0 sites with dozens of libraries and to 4.8 and it was just tedious, not hard or long. You start with the highest level first. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, November 21, 2020 8:47 PM
  • User-234441352 posted

    ok thank you bruce. I try for it and 'll inform you.

    Sunday, November 22, 2020 8:22 AM