Link to home
Start Free TrialLog in
Avatar of giancarlo barraza
giancarlo barraza

asked on

Special Redirect Code

Hi,

I have a client that needs to get a simple script function that will be stored in the jquery file and be called from an html site that will call the customized jquery file.

The code has to redirect "X" percent of the outbound clicks (links from the site taking to an external site) to a predefined link that will be in the function hidden in the JQuery source file.

Something like this:

if ((window.location.host != window.location.href) && (Math.random() <= 0.8)) { window.location.href = 'http://FIXED-SITE-FOR-REDIRECTION.com'; }


Thanks in advance!
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Please don't do that -- any time you have a site behavior that tricks the client and behaves in a random manner, you're creating a design that destroys human trust.  My reaction to such a behavior would be to report it as a potential attack site to Google and never come back.

There may be better ways to accomplish the objective, perhaps via use of an API.  Can you tell us a little more about what you're trying to do - just in plain-language non-technical terms.  If we recognize the design pattern or if you can show us other sites that do something like this, perhaps we can suggest a better approach.
Avatar of nap0leon
nap0leon

Depending on what you are trying to do... it sounds like you are thinking about it backwards.
Rather than randomize the click behavior, change the href for x% of page hits.
e.g., when the page loads, run a function that updates the link's href for x% of the users.

If you are trying to do a "20% of clicks are winners, click to find out" (and you don't the link's href to give away whether they are a winner or a loser), the link should go to a single page which uses server-side code to determine if the user is a winner or loser and either redirects to the appropriate page or loads the appropriate content.
ASKER CERTIFIED SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America 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
^^ Scott -- good suggestion!