Last active
April 2, 2020 10:32
-
-
Save tomhat/0a2ae4bd5b3f244817045044e69f61eb to your computer and use it in GitHub Desktop.
Mlritz クロスドメインパラメータ引き継ぎ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(g){ | |
var KEYNAME = 'yclid'; | |
var TARGET_URL = 'https://www.mlritz.com/shop.php'; | |
if( 'KEYNAME' in g ){ | |
KEYNAME = g.KEYNAME; | |
} | |
if( 'TARGET_URL' in g ){ | |
TARGET_URL = g.TARGET_URL; | |
} | |
var params = (function(query){ | |
if( !query || query.length < 1 ) return null; | |
var params = query.split('&'); | |
var result = {}; | |
for( var i = 0,len = params.length;i < len;i++){ | |
var elem = params[i].split('='); | |
var key = decodeURIComponent(elem[0]); | |
var val = decodeURIComponent(elem[1]); | |
result[key] = val; | |
} | |
return result; | |
})(location.search.substring(1)); | |
if( KEYNAME in params ){ | |
g.addEventListener('DOMContentLoaded', function(){ | |
var forms = g.document.querySelectorAll('form'); | |
for( var i = 0,len = forms.length;i < len;i++ ){ | |
var form = forms[i]; | |
var url = form.getAttribute('action'); | |
if( url.indexOf(TARGET_URL) >= 0 ){ | |
var sep = '?'; | |
if( url.indexOf('?') >= 0 ){ | |
sep = '&'; | |
} | |
form.setAttribute('action',url+=sep+KEYNAME+'='+params[KEYNAME]); | |
} | |
} | |
}); | |
} | |
})(this) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment