【发布时间】:2023-02-08 03:49:09
【问题描述】:
我有一个网页,在其中嵌入了捐赠表格。当捐助者访问时,他们会使用末尾带有源代码的链接进行访问。我已经弄清楚如何将源代码添加到嵌入的 URL。这是我的代码:
$(document).ready(function(){
//Step 1: this outputs the window URL source code
var results = null
$.urlParam = function(name){
results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
return results[1] || 0;
};
console.log(decodeURIComponent($.urlParam('source')));
//Step 2: this outputs the full qGiv div and script copied from qGiv
var qGivURL = $("#donation-form").html();
console.log(qGivURL);
//Step 3: this replaces the source codes
var twoVar = $(".qgiv-embed-container").attr("data-embed");
var finalURL = twoVar + "?source=" + results;
console.log(finalURL);
});
这是嵌入式代码:
<div id="donation-form">
<div class="qgiv-embed-container" data-qgiv-embed="true" data-embed-id="65951" data-embed="https://secure.qgiv.com/for/sote/embed/65951/" data-width="630"></div>
<script>(function(w, d, s, id){var js, fjs = d.getElementsByTagName(s)[0];if (d.getElementById(id)) return;js = d.createElement(s); js.id = id;js.src = "https://secure.qgiv.com/resources/core/js/embed.js";fjs.parentNode.insertBefore(js, fjs);})(window, document, 'script', 'qgiv-embedjs');</script>
</div>
我的问题是事件,虽然这行代码可以工作var finalURL = twoVar + "?source=" + results;,但它添加了 ?source=code 两次。
有人可以帮助我理解为什么会发生这种情况以及如何解决吗?
TIA!
【问题讨论】:
标签: javascript jquery utm-tracking