頁面被iframe與無刷新更換url方法


  1. 頁面被iframe問題解決方法

     if (window.top.location !== window.self.location) {
             const data = JSON.stringify({ iframedRedirectSuccess: true });
             window.top.location.href = addURLParam(window.self.location.href, 'data', data);
           }
    
  2. 頁面初始化獲取參數

     import URL from 'url-parse';
     const {
         origin, protocol, host, hostname, port, query, hash,
       } = new URL(document.URL, true);
     
       const hostInfo = {
         origin, protocol, host, hostname, port, query, hash,
       };
    
  3. 頁面無刷新刪除url上參數(僅適用於無跨域更換url及參數)

      import qs from 'querystringify';
      import omit from 'lodash/omit';
      const param = omit(qs.parse(window.location.search), ['data']);
         const paramStr = qs.stringify(param, '?');
         const url = `${window.location.pathname}${paramStr}`;
         // This is for firefox will reload previous url when we click refresh button or press F5
         // after we use replaceState to replace a new url issue.
         window.location.hash = window.location.hash; // eslint-disable-line 
         window.history.replaceState && window.history.replaceState({}, null, url);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM