2016-12-26 30 views
0

清除index.html文件看起來像這樣目前:科爾多瓦 - 在IFRAME localStorage的大幹快上的應用程序重啓

<!DOCTYPE html><html><head style="overflow: hidden; margin:0; padding:0;border:0;"> 
    <meta charset='UTF-8'/> 

    <meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'" /> 
</head> 
    <body style="overflow: hidden; margin:0; padding:0; width:100vw; height:100vh;border:0;"> 
     <iframe src="http://domain.com" style="overflow: hidden; margin:0; padding:0; width:100vw; height:100vh;border:0;"></iframe> 
    </body> 

    <script type=text/javascript> 
     alert(window.localStorage.getItem("aaa")); 
     window.localStorage.setItem("aaa", "111") 
    </script> 
</html> 

警報腳本並得到應用重啓堅持

但是iframe使用的localStorage,在應用程序重新啓動時得到清除使iframe的使用不等於僞造意圖。

回答

0

您的應用程序的localStorage不會與遠程域共享,因爲localStorage只是域特定的,所以您需要使用不同的技術來傳遞任何共享數據。以下是幾種方法:

  1. 將該值作爲查詢字符串參數傳遞給iframe URL。您可以隨時將iframe附加到DOM等,或者在移動到SPA時首先在其他位置預先加載localStorage值。

  2. 使用更常見的技術讓您的父頁面向iframe發送postMessage並將代碼添加到iframe中監聽message事件。

    https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage

關於如何發送/免費獲贈postMessage的其他細節

相關問題