Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8946847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:36:13+00:00 2026-06-15T12:36:13+00:00

Below is what I have. var myString = http://localhost:8888/www.smart-kw.com/; alert(myString.indexOf(localhost)); This give me alert…

  • 0

Below is what I have.

var myString = "http://localhost:8888/www.smart-kw.com/";
alert(myString.indexOf("localhost"));

This give me alert… however if I change var myString = "http://localhost:8888/www.smart-kw.com/"; to var myString = window.location;, it won’t work (I don’t get alert).

var myString = window.location;
alert(myString.indexOf("localhost"));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:36:14+00:00Added an answer on June 15, 2026 at 12:36 pm

    window.location is an accessor property, and getting its value gives you an object, not a string, and so it doesn’t have an indexOf function. (It’s perfectly understandable that people sometimes think it’s a string, since when you set its value, the accessor property’s setter accepts a string; that is, window.location = "some url"; actually works. But when you get it, you don’t get a string.)

    You can use window.location.toString(), String(window.location), or window.location.href to get a string for it if you like, or use any of its various properties to check specifics. From the link, given example url http://www.example.com:80/search?q=devmo#test:

    • hash: The part of the URL that follows the # symbol, including the # symbol. You can listen for the hashchange event to get notified of changes to the hash in supporting browsers.
      Example: #test
    • host: The host name and port number.
      Example: www.example.com:80
    • hostname: The host name (without the port number).
      Example: www.example.com
    • href: The entire URL.
      Example: http://www.example.com:80/search?q=devmo#test
    • pathname: The path (relative to the host).
      Example: /search
    • port: The port number of the URL.
      Example: 80
    • protocol: The protocol of the URL.
      Example: http:
    • search: The part of the URL that follows the ? symbol, including the ? symbol.
      Example: ?q=devmo

    For instance, for your quoted example, you might check window.location.hostname === "localhost".

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the below HTML code <a href=http://www.google.com>Google</a> When I click on the link,
I have the jQuery below http://jsfiddle.net/XMdYw/7/ var elements = ''; var ELEMENT_COUNT_PER_PAGE = 301;
I have got below string values in a variable. var mystring = '{img_src:/english/images/spa.jpg, img_title:Enjoy
I have below script: $(document).ready(function () { $(#dpProject).change(function () { var idModel = $(this).val();
I use CakePHP 2.0 I am following this guide http://nuts-and-bolts-of-cakephp.com/2009/01/19/jquery-in-the-cakephp-world-part-1/ I have included in
Hi I have written below code function unique(th){ var obj = {}; for(var i
I have code as below: var s : String = hello world var xml
I have a JSON array like below: var jsonArray = [{k1:v1},{k2:v2},{k3:v3},{k4:v4},{k5:v5}] I don't know
I have a simple LINQ-to-Entities query as below: var BillingNumbers = from o in
I have a datagridview which I fill it as below : var q= repository.GetStudents();//

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.