Home >Web Front-end >JS Tutorial >JS gets the url link string location.href_basic knowledge

JS gets the url link string location.href_basic knowledge

WBOY
WBOYOriginal
2016-05-16 17:07:401223browse

js to obtain the url link string: location.href

can intercept it to obtain the transmitted parameters. Commonly used are as follows:

location.href.indexOf("?")--- ---Get? index value.

Note: The location.href here does not refer to the current address in the address bar, but the actual address of the page.

In addition, some digressions:

In C#, IndexOf is also used to obtain the index of the character position.

Getting the index in sqlserver is different:

The first one:

select * from dbo.users where CharIndex('2',mainsubjects)>0

The second method:
select * from dbo.users where patIndex('%2%',mainsubjects)>0

I use the judgment column to determine whether the advertisement should be displayed :

Only content in the http://www.jb51.net/codes/ directory will display ads:

Copy code The code is as follows:

if(location.href.indexOf("http://www.jb51.net/codes/")>-1){
alert('ok');
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn