码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2019-08-30 17:23:46      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:gif   arch   hostname   删除   state   col   das   tor   click   

  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);

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

标签:gif   arch   hostname   删除   state   col   das   tor   click   

原文地址:https://www.cnblogs.com/weilantiankong/p/11435976.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!