Special Redirect Code


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!
giancarlo barrazaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
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.
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.
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
You can also set up A/B split testing/experiments in google analytics.  As the others have already said, before we go into too much detail, getting a better understanding of the end result you are trying to achieve will be helpful to give you an answer.  


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
^^ Scott -- good suggestion!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.