简体   繁体   中英

Passing 2 URL Parameters?

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.

//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:

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM