开发者

How provide results based on the query results in a url?

开发者 https://www.devze.com 2023-01-16 16:37 出处:网络
Is there a javascript solution to read the url,create a string from it, and build a if statement based on the results?Does anyone know of a tutorial or can provide me with some tips of how to accompli

Is there a javascript solution to read the url,create a string from it, and build a if statement based on the results? Does anyone know of a tutorial or can provide me with some tips of how to accomplish this.

To be more specific I am trying to do this开发者_如何转开发 based on a search result. So.. for example the url is something like:

http://www.site.com/catalogsearch/result?q=asdf&kw=asdf&x=0&y=0

and working off of Daniels response I am trying this with no luck:

if (window.location.search ==='?q=asdf') {
alert("You searched for asdf");
}


You can get the URL, or parts for it, using the window.location object.

For example, consider the following URL:

http://www.google.com:80/search?q=devmo#test

These are the standard properties of the window.location object, and the value you would get for the above URL:

property   | value
-----------+-----------------------------------------------------
hash       | #test
host       | www.google.com:80
hostname   | www.google.com
href       | http://www.google.com:80/search?q=devmo#test
pathname   | /search
port       | 80
protocol   | http:
search     | ?q=devmo

For example, if you want to check the pathname, you could do the following:

if (window.location.pathname === '/search') {
   // do something
}


how about this

var str = window.location.href; 
if(str.indexOf("http") > - 1){
 //ah an if statment!
alert("url has http");
}
0

精彩评论

暂无评论...
验证码 换一张
取 消