检查页面上的文本,然后重定向

check for text on page and then redirect

本文关键字:然后 重定向 文本 检查      更新时间:2023-09-26

如果我的页面说:

"代码不连贯,请重试"

那么我的 URL 重定向应该是:

http://site.site.co.uk/index.php#contact

我想使用 Jquery,但不确定如何在页面上检查这一点然后重定向?

我试过:

$("div#contact-form:contains('Code incorect please try again')").attr("location","http://site.site.co.uk/index.php#contact");

您可以使用

以下内容:

if ($("#contact-form").is(":contains('Code incorect please try again')")) {
    window.location.href = "http://site.site.co.uk/index.php#contact";
}

如果它是一个内部服务器的东西(或者你是精确的,任何说无论如何都应该重定向的页面),js 不会帮助你。 为此,您需要查看 Web 服务器 - 如果想到 Apache,mod_proxy,或者其他一些模块可以评估 Apache 的 req/res 链并从那里开始(如果它类似于 mod_perl, 这不是很有趣)。IIRC,你可以用nginx做类似的事情。

但是,如果这是一个JS事件,请绑定到其中并更改window.location或其他什么。

这样做

:-

if ($("div#contact-form:contains('Code incorect please try again')").length == 1)
    window.location.replace("http://site.site.co.uk/index.php#contact"); 

参考演示

var myDiv = $('div#contact-form:containt('Code incorrect please try again'));
if(myDiv.length === 0) {
    location = "http://site.site.co.uk/index.php#contact";
}