JS judge whether it is the first page, 404 pages

Source: Internet
Author: User

/*

Determine if it is the home page

*/

function Ishomepage () {

var localurl = window.location.href;

var regex = new RegExp ("^https?:/ /(test-)? www\.4008000000.com (/?| /index[(. | _)].*|/? [?]. *) $ "," I ");

Return Regex.test (Localurl);

}


/**

* Determine if the page is 404

*/

function Isfindpage () {

var localurl = window.location.href;

var regex = new RegExp ("^https?:/ /(test-)? www\.4008000000.com (/?| /404[(. | _)].*|/? [?]. *) $ "," I ");

Return Regex.test (Localurl);

}



function Common_search_baoxian (str) {

var keyword= $ (' #keyword '). Val ();

var searchvalue = $.trim (keyword);

if (""! = str) {

Searchvalue = str;

$ (' #keyword '). val (str);

}

If it is not the first page, search box empty check

if (!ishomepage () && (Searchvalue = = "" | | Searchvalue = = Defalutsearchkeyword[0].defalutkeyword)) {

$ (' #keyword '). Val (Defalutsearchkeyword[0].defalutkeyword);

$ (' #keyword '). CSS ("Color", "#666666");

Return

}

var reg =/^\s+|\s+$/g;

var searchvalueobj = getdefalutsearchkeywordobj (Searchvalue);

If it is the first page, then the special keyword check jump

if (((Ishomepage () | | isfindpage ()) && (Searchvalue.replace (Reg, ") = =" "| | Searchvalue = = Searchvalueobj.defalutkeyword | | Searchvalue = = Searchvalueobj.keyword)) | | (!ishomepage () && searchvalue = = Searchvalueobj.keyword)) {        

$ (' #keyword '). Val (Searchvalueobj.keyword);

$ (' #keyword '). CSS ("Color", "#ABA9A9");

window.open (Searchvalueobj.keywordurl + "? keyword=" + encodeURIComponent (Searchvalueobj.keyword), "_blank");

}

else{

var emallcontext = "http://www.4008000000.com/zixun/baoxian/search/search_list.shtml";

var httpurl = Emallcontext + '? keyword= ' + encodeURIComponent (searchvalue);

//window.open (httpurl, "_blank");

Window.location.href=httpurl;

}

}


JS judge whether it is the first page, 404 pages

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.