PDA

View Full Version : Restricting usage to my domain?


Zeph
07-06-2004, 07:10 PM
Hi all, I'm pretty much as newbie as one can get. I can do timelines, transitions, that's about it, but I'm a programmer, so I'm sure I can handle whatever answers I get.

My client has asked me to build a flash presentation, but wants to prevent others from running it on their site. I can restrict leeching with a .htaccess, so that's good.

On loading, I would like to use actionscript to get the movie to check the current domain, if it does not match the domain embedded in a movie, it redirects to the owner's domain. Pseudo code to illustrate:


var myDomain = "http://www.mydomain.com";
function checkDomain ()
{
c = currentDomain();
if (c != myDomain)
{
stop();
redirect (myDomain);
}
}
onLoad (checkDomain);

At the very least, if I can't redirect, I'd like to be able to stop the flash and display a frame with "Please visit http://www.mydomain.com."

Can someone suggest how I can go about doing this?

Thank you.

tg
07-06-2004, 08:09 PM
try this code:

var myDomain="http://www.actionscript.org";
function checkDomain(){
var current=this._url;
if(current.substr(0,myDomain.length)!=myDomain){
this.getURL(myDomain,"_self");
}
};
checkDomain();


this._url doesn't give your the current domain, it does give your the page address of the page that has the swf embedded in it. so then i just strip out the first part of the url to see if it matchs the domain you want to look at.

Zeph
07-06-2004, 08:41 PM
Beauty! Worked like a charm. Thank you.