我有一个表单可以对其他网站进行GET,并希望在提交表单时使用?_ga=
跟踪器ID。我有这个跟踪器clientId在常规链接上正常工作,但不知何故不能让它在下面的表单上工作。
<form action="" method="get" name="iform" id="iform" target="_blank">
<div class="form-items">
<div class="form-item fas-feedback date date-1">
<label for="DateIn">From</label>
<input type="text" class="check-date-from" id="check-in" name="DateIn" readonly placeholder="DD-MM-YYYY" />
</div>
<div class="form-item fas-feedback date date-2">
<label for="DateOut">Till</label>
<input type="text" class="check-date-to" id="check-out" readonly name="DateOut" placeholder="DD-MM-YYYY" />
</div>
</div>
<div class="form-action long-transition">
<button>Submit</button>
</div>
</form>
脚本:
var clientId;
$(document).ready(function() {
ga(function(tracker) {
clientId = tracker.get('clientId');
});
$("#iform").submit(function(e) {
e.preventDefault();
var uri = 'https://engines.hoteliers.com/en/3456789/whitelabelplus/getdata/arrival/'+$("#check-in").val()+'/departure/'+$("#check-out").val()+'/type/roomonly/?clientId='+clientId;
window.open(uri, '_blank');
return false;
})
});
任何帮助都会很棒!
答案 0 :(得分:0)
尝试
$(document).ready(function() {
$("#iform").submit(function(e) {
e.preventDefault();
var clientId = ga.getAll()[0].get('clientId');
var uri = 'https://engines.hoteliers.com/en/3456789/whitelabelplus/getdata/arrival/'+$("#check-in").val()+'/departure/'+$("#check-out").val()+'/type/roomonly/?clientId='+clientId;
window.open(uri, '_blank');
return false;
});
});