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!
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!
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
^^ Scott -- good suggestion!
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.