I need a reliable way to get the current URL in the browser using javascript, and to test whether a string is contained in the url.
Is this a safe process between all the browsers?
I need a reliable way to get the current URL in the browser using javascript, and to test whether a string is contained in the url.
Is this a safe process between all the browsers?
You could use .indexOf() against the window.location.href, but be aware that you're testing the entire url.
if( window.location.href.indexOf( 'someString' ) != -1 ) {
alert( 'the string was found' );
}
Array.indexOf(). This is String.indexOf().I really like the jQuery URL Parser to work against the URL in JavaScript. It is a great utility to get various parts of the URL and compose new ones.