
import util from './util';

/**
 * @namespace
 *
 */
var urlUtils = {

  /***
   * @param {String} url
   * @type String
   */
  getOrigin:function( url ){
    var result = /https?:\/\/[^/]*\/?/.exec( url );
    return result.length ? result[0] : null;
  },

  /** 
   * @param {HTMLElement} el
   * @type Object
   */
  getOriginByFrameEl:function( el ){

    return util.isElement( el ) ? urlUtils.getOrigin( el.src ) : document.referrer;
  }
};

export default urlUtils;



import util from './util';

/**
 * @namespace
 *
 */
var urlUtils = {

  /***
   * @param {String} url
   * @type String
   */
  getOrigin:function( url ){
    var result = /https?:\/\/[^/]*\/?/.exec( url );
    return result.length ? result[0] : null;
  },

  /** 
   * @param {HTMLElement} el
   * @type Object
   */
  getOriginByFrameEl:function( el ){

    return util.isElement( el ) ? urlUtils.getOrigin( el.src ) : (document.referrer ? document.referrer : urlUtils.getOrigin(document.location.href));
  }
};

export default urlUtils;


Return current domain if the document.referrer is empty string (dynamic iframe created)
Return current domain if the document.referrer is empty string (dynamic iframe created)
