用于检查当前页面的URL的脚本... [英] A script to check the URL of the current page...

查看:69
本文介绍了用于检查当前页面的URL的脚本...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我知道这一定非常简单,但我对

JavaScript的了解是相当基础的,我过去学到的东西我学到了

对于非常具体的情况,所以我没有明确的工作知识。


我想制作一个简单的脚本将检查位置键入

到用户的地址栏中,如果它包含某个域名,那么

将调用一个函数(不知道还有什么...也许可以在页面上添加文字,

可能会创建一个警报,可能是警报和重定向)。主要的

概念是将人们引导到我的新域名,即使我是以b
$ b托管它作为镜像,所以我可以让我的旧域名失效。 br />

那么......关于如何做到这一点的任何建议?赔率是难以置信的简单,但我的大脑现在还没有锁定语言。


谢谢,


TurboFool

Alright, I know this must be incredibly simple, but my knowledge of
JavaScript is rather basic, and what I''ve learned in the past I learned
for highly specific situations, so I don''t have a clear working
knowledge of it.

I''m looking to make a simple script that will check the location typed
into the user''s address bar and if it contains a certain domain name it
will call a function (not sure what yet... maybe add text to the page,
maybe create an alert, maybe an alert and a redirect). The main
concept is to direct people to my new domain name even though I''m
hosting it as a mirror so I can let my old domain name lapse.

So... any suggestions on how to do this? Odds are it''s incredibly
simple, but my brain just isn''t latching onto the language right now.

Thanks,

TurboFool

推荐答案

我想你可以做到这一点。


if(" MY_OLD_DOMAIN" .indexOf(location.host)!= -1)

{

//重定向到您的新域名。

}


谢谢

Sanjay

I guess you can do this.

if ("MY_OLD_DOMAIN".indexOf(location.host) != -1 )
{
//redirect to your new domain.
}

Thanks
Sanjay


Sanjay写道:
Sanjay wrote:
我想你可以这样做。

if(" MY_OLD_DOMAIN" .indexOf(location.host)!= -1)
{
//重定向到你的新域。
}
I guess you can do this.

if ("MY_OLD_DOMAIN".indexOf(location.host) != -1 )
{
//redirect to your new domain.
}




因为MY_OLD_DOMAIN
$因此反过来更有意义b $ b是你在location.host中寻找的,反之亦然:


if(location.host.indexOf(" MY_OLD_DOMAIN")!= -1)

{

//重定向到您的新域。

}


但请记住:< URL:http://www.w3.org/QA/Tips / reback>

PointedEars



It makes more sense the other way around because "MY_OLD_DOMAIN"
is what you are looking for in location.host, not vice-versa:

if (location.host.indexOf("MY_OLD_DOMAIN") != -1)
{
// redirect to your new domain.
}

But remember: <URL:http://www.w3.org/QA/Tips/reback>
PointedEars


Thomas''PointedEars''Lahn写道:
Thomas ''PointedEars'' Lahn wrote:
其他更有意义因为MY_OLD_DOMAIN
是你在location.host中寻找的,反之亦然:

if(location.host.indexOf(" MY_OLD_DOMAIN")!= -1)
//重定向到您的新域名。


但请记住:< URL:http://www.w3.org/ QA / Tips / reback>
It makes more sense the other way around because "MY_OLD_DOMAIN"
is what you are looking for in location.host, not vice-versa:

if (location.host.indexOf("MY_OLD_DOMAIN") != -1)
{
// redirect to your new domain.
}

But remember: <URL:http://www.w3.org/QA/Tips/reback>




嗯,我更有可能使这个脚本添加文本链接

页面通知他们更改,或者当他们点击确定按钮时创建一个警告,将他们带到新页面。


有关最好的建议实现后者的方法,尤其是一个我不需要定制鳕鱼的b $ b脚本e我网站上每个

页面的地址(换句话说,如果他们访问my.old.domain / resume.html

,脚本会自动将它们带到我的网站。 new.domain / resume.html

或他们访问的其他地址)?我知道我已经深入到这里

我可能会满足于您提供的剧本(非常感谢,

你们两个),但是很多这是比较简单的事情吗?



Well, I''d be more likely to make this script either add a text link to
the page notifying them of the change, or create an alert that takes
them to the new page when they hit the OK button.

Any suggestions on the best way to implement the latter, especially a
script that I wouldn''t have to custom code the address of for every
page in my site (in otherwords if they access my.old.domain/resume.html
the script would automatically take them to my.new.domain/resume.html
or whatever other address they accessed)? I know I''m getting deep here
and I may just settle for the script you provided (thank you very much,
both of you), but prhaps there''s something relatively simple?


这篇关于用于检查当前页面的URL的脚本...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆