Home > Features > More Surfer Redirection Using JavaScript • Bookmark   • Newsletters   • Register Search Options


More Surfer Redirection Using JavaScript

More Surfer Redirection Using JavaScript

September 25, 2001
Text size: 
Get XBIZ News
XBIZ Research
Will virtual reality boost the paysite market?
Yes, it will soon
Yes, but in a few years
Out of 179 votes. Results based on votes submitted by members of XBIZ.net social network.

" This is great for high bandwidth Web pages that you want to limit free access to. "

Quite a readers enjoyed last week's Surfer Redirection Using JavaScript article, and a few of you wanted to know more about using JavaScript to manage your site's traffic. Here are a few more of my favorite redirection scripts, and some suggestions on how to use them...

Referrer Redirect
Being able to redirect surfers based upon the page they came from can provide you with many benefits, including the ability to target advertising and entry pages, as well as language settings and other user-specific enhancements. You can also use this script for a rudimentary security gate, ensuring that visitors to your member's area came through your AVS script page.

Place the following lines inside of your <HEAD></HEAD> tag. You will need to insert the page destination you wish to send the surfer where it says REDIRECTION PAGE as well as your BASE URL; the page that must refer the surfer:

<SCRIPT language="JavaScript">
<!-- Referrer Redirect
function check(){
referingDoc = document.hide.ref.value
if (referingDoc != ("")){
if (referingDoc.indexOf("BASE URL") == -1){;
window.location = "REDIRECTION PAGE"}
// Referrer Redirect -->

Now put the following lines inside of your <BODY> code:

<BODY onLoad="check()">

Finally, place this code after your <BODY onLoad="check()"> tag:

<FORM name=hide><INPUT type=hidden name=ref></FORM>
<SCRIPT>document.hide.ref.value = document.referrer; </SCRIPT>

New User Redirect
Using cookies to determine if the user has been to your page before, this script redirects first time visitors to a new page. This is really handy for setting up a special greeting or help page.

Put these lines inside of your <HEAD></HEAD> tag, modifying the REDIRECT URL and COOKIE NAME (choose something "unique") to the appropriate values:

<SCRIPT language="JavaScript">
<!-- New User Redirect
var caution = false
function setCookie(name, value, expires, path, domain, secure) {
var curCookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "")
if (!caution || (name + "=" + escape(value)).length <= 4000)
document.cookie = curCookie
if (confirm("Cookie exceeds 4KB and will be cut!"))
document.cookie = curCookie
function getCookie(name) {
var prefix = name + "="
var cookieStartIndex = document.cookie.indexOf(prefix)
if (cookieStartIndex == -1)
return null
var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
if (cookieEndIndex == -1)
cookieEndIndex = document.cookie.length
return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
function deleteCookie(name, path, domain) {
if (getCookie(name)) {
document.cookie = name + "=" +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT"
function fixDate(date) {
var base = new Date(0)
var skew = base.getTime()
if (skew > 0)
date.setTime(date.getTime() - skew)
var now = new Date()
now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000)
var visits = getCookie("COOKIE NAME")
if (!visits)
location = "REDIRECT URL"
setCookie("COOKIE NAME", visits, now)
// New User Redirect -->

Time Based Redirect
This simple JavaScript alternative to cookie-based solutions will send visitors to a specified URL after a set period of time. This is great for high bandwidth Web pages that you want to limit free access to. Perhaps you could even use it to set up a "limited time free trial" to a webcam or other video feed, sending surfers to the join form for more. The possibilities are endless...

Put these lines inside of your <HEAD></HEAD> tag:

<SCRIPT language="JavaScript">
<!-- Time Based Redirect
function startTimer(){
var time= new Date();
hours= time.getHours();
mins= time.getMinutes();
secs= time.getSeconds();
function Timer(){
var time= new Date();
hours= time.getHours();
mins= time.getMinutes();
secs= time.getSeconds();
location = "YOUR URL"
function timeLeft(){
count = closeTime-curTime;
// Time Based Redirect -->

Now put the following lines inside of your <BODY> code:

<BODY onLoad="startTimer()">

Finally, change closeTime+=10; to reflect the amount of seconds to wait before page redirect, and change location = "YOUR URL" to the URL you wish to send the surfer.

I hope that you find this collection of surfer redirection tools useful. They can open up new possibilities for your traffic management planning, and help you to increase your profitability. Don't be afraid to experiment, either. Combine bits and pieces of several scripts together and develop a solution unique to YOUR needs. Good luck!


Porn ‘Public Health Crisis’ Is False, Dangerous

We are witnessing the early stages of a moral panic, the likes of which we have not seen since the Reagan Administration. As I write this, there are 27 states in the process of passing mandatory porn... More »

The Skinny on the New DMCA Requirement

The requirements under the Digital Millennium Copyright Act (DMCA) have changed, but the sky is not falling. We have, even as a law firm, been hit with an unbelievable amount of spam sent out by law firms... More »

2017 Outlook: Legal Matters Around the Corner

The adult entertainment business’ legal community recently weighed in the top issues that companies and the industry, as a whole, should be concerned about. XBIZ asked industry attorneys to discuss... More »
Stay informed of the latest industry developments. Get XBIZ newsletters delivered to your inbox. Subscribe today!
Enter email address:

* To manage existing subscriptions click here.

Submit your press release to
multiple news outlets with 1 click.
Subscribe to RSS news feeds or
add free content to your website.
Access XBIZ news and articles
with your mobile device.
Subscribe to XBIZ Premiere magazine, the industry's leading adult retail trade publications, delivering the most timely and comprehensive business news and information to producers and retailers of adult products.


XBIZ.net Paysite Meetup

May 04 - May 04
Prague, Czech Republic

Eurowebtainment 2017

May 17 - May 20
Majorca, Spain

XBIZ Retreat

May 30 - Jun 03
Miami, Florida

XBIZ Miami 2017

May 30 - Jun 02
Miami, Florida
Everyday thousands of business professionals browse XBIZ's industry directory for quality products and services. Not listed yet? Your company could be losing potential new business. Submit your company today!
Use XBIZ RSS feeds to stay informed of the latest industry developments or as a content syndication tool for your website!