传递 2 个 URL 参数?

发布于 2024-12-20 13:59:30 字数 903 浏览 1 评论 0原文

我需要在 URL 中传递 2 个 URL 参数。该 URL 源自电子邮件,用户将单击该链接将他们定向到我的网站。第一个参数触发页面上的脚本,第二个参数用于我的 CMS 将从该参数呈现的模块。

第一个参数是:message=1(此参数触发 javascript)

第二个参数是:name={tag_recipientfirstname}(我的 CMS 将呈现该模块)

该脚本是第一个的调用看起来像这样:

    <script type="text/javascript">
var $j = jQuery.noConflict();
$j(document).ready(function() {
var url = window.location.href;
url = url.toLowerCase();
if (url.indexOf('message=1') != -1) {
        $j("a.message").colorbox({
            open:true
});
   }
$j("a.message").colorbox(); //not related to URL parameter
}); 
</script>

第二个参数在页面上使用为:

<div>
<p>{ module_url,name} (again CMS will render this module)</p>
</div>

编辑

我意识到我遗漏了几件事:

第一:如何传递两个参数所以它们都将充当上面列出了?

我使用的CMS是Business Catalyst。

I need to pass 2 URL parameters in a URL. The URL originates in an email and the user will click the link directing them to my site. The first parameter triggers a script on the page the second parameter is for a module my CMS will render from the parameter.

First Parameter is : message=1 (This parameter triggers the javascript)

The second Parameter is: name={tag_recipientfirstname} (My CMS will render the module)

The script that is called for the first looks like this:

    <script type="text/javascript">
var $j = jQuery.noConflict();
$j(document).ready(function() {
var url = window.location.href;
url = url.toLowerCase();
if (url.indexOf('message=1') != -1) {
        $j("a.message").colorbox({
            open:true
});
   }
$j("a.message").colorbox(); //not related to URL parameter
}); 
</script>

The second parameter is used on the page as:

<div>
<p>{ module_url,name} (again CMS will render this module)</p>
</div>

EDIT

I realize I left a couple things out:

First: How do I pass both parameters so they will both function as listed above?

And the CMS I am using is Business Catalyst.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

捶死心动 2024-12-27 13:59:30
//split the `location.search` string at the ampersands
var search_arr = window.location.search.replace('?', '').split('&'),
    len        = search_arr.length,
    get_vars   = {},
    tmp        = [];

//iterate through the key/value pairs and add them to the `get_vars` object
for (var i = 0; i < len; i++) {
    tmp = search_arr[i].split('=');
    get_vars[tmp[0]] = tmp[1];
}

//you can now access your GET variables through the `get_vars` object like: `get_vars.name`

//you can check for the existence of a certain GET variable like this
if (typeof(get_vars['message-1']) != 'undefined') {
    $j("a.message").colorbox({
        open:true
    });
}

这是一个演示:http://jsfiddle.net/aBH8K/1/(http://jsfiddle.net/aBH8K/1/show/?message-1=3用get var查看)

一些相关文档:

//split the `location.search` string at the ampersands
var search_arr = window.location.search.replace('?', '').split('&'),
    len        = search_arr.length,
    get_vars   = {},
    tmp        = [];

//iterate through the key/value pairs and add them to the `get_vars` object
for (var i = 0; i < len; i++) {
    tmp = search_arr[i].split('=');
    get_vars[tmp[0]] = tmp[1];
}

//you can now access your GET variables through the `get_vars` object like: `get_vars.name`

//you can check for the existence of a certain GET variable like this
if (typeof(get_vars['message-1']) != 'undefined') {
    $j("a.message").colorbox({
        open:true
    });
}

Here is a demo:http://jsfiddle.net/aBH8K/1/ (http://jsfiddle.net/aBH8K/1/show/?message-1=3 to see with get var)

Some related documentation:

別甾虛僞 2024-12-27 13:59:30

您的问题与其说是关于通用开发,不如说是关于非常具体的商业产品;我不知道您向他们订阅了哪个计划(免费或付费?),但无论如何,最好得到他们的支持(另请参阅我的结论),

尽管如此,我会尽力让您走上正轨。

您的问题

首先,

电子邮件中的网址

在电子邮件中,您将能够以某种方式建立一个包含您想要的两个参数的链接,正如 @Jasper 所解释的那样。
这意味着:

http://yourwebsite.com/destination/path/?message=1&name={tag_recipientfirstname}

问号后面的所有内容都是 GET 查询字符串
参数之间用“&”分隔象征。

我绝对不知道如何在 BC 电子邮件中正确构建 url,但我觉得它应该是一个自动化的地方,允许您在需要时指定其他参数。

javascript

你得到的 仍然可以工作。这不是很好,您可以使用 Jasper 的解决方案或任何其他解决方案,例如 我怎样才能得到在 JavaScript 中查询字符串值?

那么什么都不用做,除非你想让它变得更好、更健壮。

Business Catalyst(页面)

通常可以在 CMS 中检索获取参数。通常会出现这样的情况:

{ GET.param_name }

退一步,

我不是 BC 方面的专家,但我有一种感觉,你正在为可能已经成熟的东西走一条复杂的道路。

我再次建议你进入他们的 支持部分(尽管我必须说这相当令人困惑!)并尝试了解实现目标的最佳方式是什么。剥一只可怜的猫的皮总是有很多种方法。
如果您的计划得到支持,一定要这样做并尝试解释您的目标是什么,而不是如何实现您认为好的技术解决方案!

Your question is not so much about generic development, rather a very specific commercial product; I do not know which plan you subscribed (free o pay-for?) with them but in any case it would be best to go through their support (see also my conclusion)

Nevertheless I'll try to put you on the right track.

Your questions

First,

the url in the email

In the email you will have somehow to build a link with the two parameters you want as @Jasper is explaining.
this means something like:

http://yourwebsite.com/destination/path/?message=1&name={tag_recipientfirstname}

Everything after the question mark is a GET query string.
Parameters are separated by the "&" symbol.

I definitely don't know how properly build urls in BC emails, but I feel like it should be an automated somewhere allowing you to specify additional parameters if you need.

the javascript

What you got will still work. It's not very nice, and you can use Jasper's solution or any other such as How can I get query string values in JavaScript?

Nothing to do then unless you want to make it better and more robust.

Business Catalyst (the page)

You usually have ways in a CMS to retrieve get parameters. Often something like

{ GET.param_name }

One step back

I am no expert with BC, but I have the feeling that you are taking a complicate path for something that is probably already baked in.

Again I suggest you go into their support section (though it's rather confusing I must say!) and try to understand what's the best way to achieve your objective. There are always many ways to skin a poor cat.
If you are getting support in your plan, definitely go that way and try to explain what you objectives are rather then how to achieve the technical solution that you think is the good one!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文