0

I found an nice script while searching and inspecting the elements of some websites.

This is what I have found:

<script type="text/javascript">
//redirect browser to fullscreen preview
    if (/^http:\/\/codecanyon\.net/.test(document.referrer))
    window.top.location.href = 'http://www.gravitysign.com/backslider/';                    
</script>

So if I understood from this script it tells jquery if the website is opened over codecanyon redirect them to specifed website for preview.

Now... I was wondering if there is possibility to make something like this.

If we specify an website for example http://google.com and we input that into javascript... And then if that website is uploaded to any other domain, other then google.com ... It will redirect to specified site (google) ?

So to clear things out a little bit let me make an example.

If I made a website for "an-website.com" and then someone take their website and upload it to "another-website.com", it will automatically redirect all visitors from another-website.com to an-website.com.

Hope I was clear enough and hope that this is possible. Cheers!

6
  • This says, if the document.referrer object matches a string starting with http://codecanyon.net, then redirect the user to a website. I'm not sure where the confusion lays. Commented Sep 12, 2012 at 19:57
  • Exactly like so... But is it possible to make something similar to it, but to say if theres any domain other then specified one, redirect to specified domain... Commented Sep 12, 2012 at 19:59
  • Are you going to use this as some kind of copy protection? Commented Sep 12, 2012 at 20:03
  • @Jørgen exactly like so... And Loktar... Whats your point with it? If I dont know what website will be referrer how to input it into javascript ? :] Commented Sep 12, 2012 at 20:07
  • @Nenad dvl But how are you going to prevent the person hosting the copy from editing your markup and removing your script? Commented Sep 12, 2012 at 20:10

2 Answers 2

1

You can of course redirect any user accessing your site from a domain not matching yours but using javascript. This should work just fine:

if (window.location.hostname !== 'yourdomain.com'){
    window.top.location.href = 'http://yourdomain.com'; 
}

You can also use match, if you host your site on a subdomain, etc.

Keep in mind that any person with write access to the file on the server will be able to remove this "copy protection". Copy protecting client side content is impossible, as you need to serve the content in a way a browser understands, effectively making the content available to anyone.

Sign up to request clarification or add additional context in comments.

Comments

0

If you are looking for solution for single domain protection, here you can see my

Redirect Website if its not specified domain in script - Protection using Javascript

I am looking for solution for multiple domain.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.