Link to home
Start Free TrialLog in
Avatar of Reveroom
Reveroom

asked on

Coldfusion, Javascript & Ampersands?

Hi Folks,

I've hit a bit of a stumbling block here and would appreciate your help.

I'm trying to pass a link between 3 sites, and the links include various parameters.  I need to use a mix of cflocation and javascript window.location (the JS required because that page also has a cfflush).

Here's an example of the workflow;

// index.cfm \\

<cfset link1 = 'http://www.domain.cfm?param1=1¶m2=2'>
<cflocation url="http://otherdomain.com/track.cfm?link=#link1#">

// track.cfm \\

<cfset link2 = '#url.link#'>
<cfflush>
<script type="text/javascript">
window.location = "<cfoutput>#link2#</cfoutput>"
</script>

This works fine, except that anything after the '&' isn't being passed.  So, the destination is only going as far as http://www.domain.cfm?param1=1

A bit of googling suggests this is a known issue, and I need to somehow escape it - but I'm not entirely sure how!

Any help would be much appreciated!
Avatar of erikTsomik
erikTsomik
Flag of United States of America image

all you need to do is to use evaluate

<cfset link2 = '#url.link#'>
<cfflush>
<script type="text/javascript">
window.location = "<cfoutput>#Evaluate(DE(Link2))#</cfoutput>"
</script>
Avatar of Reveroom
Reveroom

ASKER

Thanks for the swift reply, erik.

It's still not working for me however.  If I do a straight cflocation to the destination url, it works fine.  However, if I do it via the 'middle domain' (which uses the window.location), it's still stripping everything after (and including) the ampersand.
try to use
location.replace
or
href.location
Hi erik,

Still the same result - have tried both alternatives without success.
what browser are using .. try using different browser so we can see if this just a browser compatability issue
Tried on both Firefox (Mac) and IE 7 (Win) - same result on both
ASKER CERTIFIED SOLUTION
Avatar of SidFishes
SidFishes
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, SidFishes - that did indeed solve the problem!  Much appreciated.

Thanks to erik once again too, your input is appreciated.