2017-11-24 10 views
-2

그래서 우리가 소유하고있는 응용 프로그램을 실행할 iframe을 기본적으로 포함하는 추가 기능을 개발 중입니다.Office 추가 기능 내에서 iframe (url)의 상태 기록

문제는 iframe의 url을 contently 기록하여 addin 상태로 저장할 수 있으므로 추가 정보가 다시 열릴 때마다 iframe을 올바른 URL로로드하는 데 해당 정보를 사용하도록하는 것입니다.

변경 될 때마다 iframe 내에서 URL을 출력하는 방법을 찾아 낼 수 없습니까? 사람들이 이유를 이해

home.html을

<!DOCTYPE html> 
<html> 
<head> 
    <meta charset="UTF-8" /> 
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" /> 
    <title></title> 
    <script src="../Scripts/jquery-1.9.1.js" type="text/javascript"></script> 
    <script src="../Scripts/FabricUI/MessageBanner.js" type="text/javascript"></script> 
    <script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js" type="text/javascript"></script> 

    <link href="Home.css" rel="stylesheet" type="text/css" /> 
    <script src="Home.js" type="text/javascript"></script> 

    <!-- For the Office UI Fabric, go to https://aka.ms/office-ui-fabric to learn more. --> 
    <link rel="stylesheet" href="https://appsforoffice.microsoft.com/fabric/2.1.0/fabric.min.css"> 
    <link rel="stylesheet" href="https://appsforoffice.microsoft.com/fabric/2.1.0/fabric.components.min.css"> 


</head> 
<body> 


</body> 
</html> 

Home.js

(function() { 
    "use strict"; 

    // The initialize function must be run each time a new page is loaded 
    Office.initialize = function (reason) { 
     $(document).ready(function() { 

      var iframew = document.createElement('iframe'); 
      iframew.src = '../SecondPage/SecondPage.html'; 
      iframew.id = 'iframe1'; 
      iframew.onload = iframeLoaded(this.contentWindow.location.href); 

      document.body.appendChild(iframew); 


     }); 
    }; 

    // Helper function for displaying notifications 

    function iframeLoaded(location) { 
     console.log("log", location); 
    } 
})(); 

답변

0

캔트 : 여기 내가 가지고있는 샘플이이 나던 응용 프로그램을 샘플 페이지의 단지 몇 포함 이 질문을 downvoting, 그것은 진짜 문제가

어쨌든, 나는이 문제를 해결하기 위해 iframe로드 후 if a load 함수를 연결하여 해결했습니다. nterval 기간

var iframew = document.createElement('iframe'); 
     iframew.id = 'iframe1'; 
     var baseUrl = '#YOUR BASE URL#'; 

     let openUrl = getProperty('openurl'); 
     if (!openUrl) { 
      console.log('No saved url'); 
      iframew.src = baseUrl; 

     } 
     else { 
      console.log('saved url'); 
      console.log(openUrl); 
      iframew.src = openUrl; 

     } 
     //when iframe loads attach function to save at interval 
     iframew.addEventListener('load', function() { setInterval(function() { iframeLoaded(iframew.contentWindow.location.hash, iframew.contentWindow.location.href); }, 4000); }); 
     document.body.appendChild(iframew); 
여기

또한 URL의 일부 조작을 수행하고 추가 기능의 doocument 설정으로 URL을 저장하는 다른 함수 호출되어 iframeLoaded 기능입니다

:

function iframeLoaded(hash, location) { 
      //if not in an analysis dont save 
      if (hash.indexOf('#/dataset/') !== -1) { 
       console.log("Same url") 
       return 
      } 
      //remove # from hash 
      hash = hash.substr(1); 
      //concatenate base and hash 
      let newUrl = baseUrl + hash; 
      console.log(hash) 
      console.log(newUrl); 
      //save 
      if (Office.context.document.settings) { 
       saveProperty('openurl', newUrl); 
      } 
     }