简体   繁体   English

JavaScript重定向/域指定

[英]Javascript redirection / domain specify

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. 因此,如果我从此脚本理解,它将告诉jquery网站是否通过codecanyon打开,并将其重定向到指定的网站进行预览。

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) ? 如果我们指定一个网站(例如http://google.com) ,然后将其输入到javascript ...中,然后将该网站上载到其他任何域,那么google.com ...将被重定向到指定的网站(谷歌) ?

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. 如果我为“ an-website.com”创建了一个网站,然后有人将其网站上传到“ another-website.com”,它将自动将所有访问者从another-website.com重定向到an-website.com。

Hope I was clear enough and hope that this is possible. 希望我足够清楚,希望这是可能的。 Cheers! 干杯!

You can of course redirect any user accessing your site from a domain not matching yours but using javascript. 当然,您可以从与您的域名不匹配但使用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. 如果您将站点托管在子域上,也可以使用match。

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. 复制保护客户端内容是不可能的,因为您需要以浏览器理解的方式提供内容,从而有效地使任何人都可以使用该内容。

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 重定向网站(如果未在脚本中指定域)-使用Java进行保护

I am looking for solution for multiple domain. 我正在寻找多个域的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM