Question: I need to check if the location is similar to some text. So my code is as below:

```
        //are we already on the same form
        var loc = window.top.window.location;
        if(loc)
           window.alert("loc=" + loc);

        if(loc && loc.search(form, "i") != -1)
        {

        }

```

The window.top.window looks a bit odd - it is used because the window might not be the topmost and I need to get the topmost instance.

I do get an instance of loc - so it is not null. But the search works?

But if I run this code I get a javascript runtime error:

```
Caught exception: Object doesn't support this action

```

Why do I get this problem?

If I cannot search how can I compare strings using a location?

EDIT

What confused me is that location does have a read-only property search which is the HTTP GET command. 

I was thinking I was doing .search on a string - but instead was attempting to write to a read-only property.

Answer: 
Try with: 

```
      window.top.window.location.href

```

You could alert only strings.
The `window.location` variable is an object, what has the `href` property, what is a string.
See the docs: <http://www.w3schools.com/jsref/obj_location.asp>

If you want to see what is inside the location object:

```
     console.log(window.top.window.location);

```

This will print something like this (in chrome):

```
    Location
      -ancestorOrigins: DOMStringList
      -assign: function () { [native code] }
      -hash: ""
      -host: "stackoverflow.com"
      -hostname: "stackoverflow.com"
      -href: "http://stackoverflow.com/posts/15863038/edit"
      -origin: "http://stackoverflow.com"
      -pathname: "/posts/15863038/edit"
      -port: ""
      -protocol: "http:"
      -reload: function () { [native code] }
      -replace: function () { [native code] }
      -search: ""
      -toString: function toString() { [native code] }
      -valueOf: function valueOf() { [native code] }
      -__proto__: Location
            ...

```
You need to use `window.top.window.location.href`! `window.top.window.location` is an object not a string.

```
    //are we already on the same form
    var loc = window.top.window.location.href;
    if(loc)
       window.alert("loc=" + loc);

    if(loc && loc.search(form, "i") != -1)
    {

    }

```

![image](https://fs.fnkr.net/FhPJ06mxyfcH/raw)