-
頁面被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); } -
頁面初始化獲取參數
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, }; -
頁面無刷新刪除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);
