13 Votes

JavaScript: window.location to String

Info by Stefan Trost | 2015-09-26 at 11:28

Even though it sometimes seems, window.location is not a string but an object. Therefore, we have to convert window.location into a string before we can use it with string functions such as .indexOf().

For converting window.location to a string, there are several possibilities:

  • var s = window.location.toString();
  • var s = window.location.href;
  • var s = String(window.location);

After that, our string variable s contains our URL so that we can further work with it.

ReplyPositiveNegative

About the Author

AvatarYou can find Software by Stefan Trost on sttmedia.com. Do you need an individual software solution according to your needs? - sttmedia.com/contact
Show Profile

 

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.