我决定重新提交这个问题,因为我可能不清楚我的问题和我的总体目标。
我目前正在处理一个仅使用 HTML 的网站。我在 URL 中传递了由 javascript 读取的变量,然后获取每个变量的参数并将其填充到 Google javascript 中。
JS 读取 URL:
function gup(name) {
var params = {};
var parts = (window.location.search || '').split(/[&?]/);
for (var i = 0; i < parts.length; ++i) {
var eq = parts[i].indexOf('=');
if (eq < 0) continue;
params[decodeURIComponent(parts[i].substring(0, eq))]
= decodeURIComponent(parts[i].substring(eq+1));
}
return Object.hasOwnProperty.call(params, name)
? params[name] : null;
}
要写入第二个 JS 的变量:
var keyValue1 = gup( 'pid1' );
写入的 Google JS 部分:
GA_googleAddAttr("pid1", keyValue1);
所有这些对我来说都工作得很好。这些参数被传递到 Google 广告中,但页面上仍然有几个没有附加“?pid1=”变量的链接。我希望能够执行以下操作之一:
-
从变量“pid1”中获取参数并将其传递到位于
中的链接中。 a>标签。 (注意:我确实有多个变量,example.com/index.html?pid1=abc&pid2=def&pid3=ghi)
-
从 URL 中剥离,以 ? 开头以及此后的所有内容,并将其附加到一个链接或位于 < 中的所有链接。 a>页面上的标记。
-
从 URL 中剥离,以 ? 开头并且仅选择一组变量并将其附加到一个链接或位于 << 中的所有链接。 a>页面上的标记。
非常重要的一点是,我的 JS 知识仅限于提出问题、获取我所得到的信息并尝试从中找出答案,这就是我希望在这里做的事情。预先感谢您提供的任何帮助。
I decided to resubmit this question because I probably was not clear on my problem and my overall objective.
I am currently working with a website using only HTML. I have variables being passed in the URL that are read by a javascript and I then take the parameter for each variable and populate it into a Google javascript.
JS reading the URL:
function gup(name) {
var params = {};
var parts = (window.location.search || '').split(/[&?]/);
for (var i = 0; i < parts.length; ++i) {
var eq = parts[i].indexOf('=');
if (eq < 0) continue;
params[decodeURIComponent(parts[i].substring(0, eq))]
= decodeURIComponent(parts[i].substring(eq+1));
}
return Object.hasOwnProperty.call(params, name)
? params[name] : null;
}
The variable to be written to the second JS:
var keyValue1 = gup( 'pid1' );
The portion of the Google JS that is written to:
GA_googleAddAttr("pid1", keyValue1);
All of this has been working quite well for me. Those parameters are passed into Google ads but I still have several links on the page that do not have the '?pid1=' variable attached. I would like to be able to do one of the following:
-
Take the parameter from the variable 'pid1' and pass it into a link located in a < a > tag. ( NOTE: I do have multiple variables, example.com/index.html?pid1=abc&pid2=def&pid3=ghi )
-
Strip from the URL, starting with the ? and everything thereafter and attach it to one link or all links located in a < a > tag(s) on the page.
-
Strip from the URL, starting with the ? and only a selected set of variable(s) and attach it to one link or all links located in a < a > tag(s) on the page.
Very important note, my JS knowledge is limited to asking questions and taking what I get and trying to figure it out from there, which is what I am hoping to do here. Thanks in advance for any help provided.
发布评论
评论(1)
我不太确定
标签是否已经在页面上,但如果是:
Im not really sure if the
<a>
tag is already on the page, but if it is: