页面被iframe与无刷新更换url方法

页面被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);

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzxxfw.html