WjNa
WjNa

Reputation: 89

str.indexOf is not a function error?

Simple, I'm doing this:

var loc = window.location;
var fltURI=loc.substr(loc.indexOf("hey?hi=")+7, loc.length);
alert(fltURI);

And I'm getting the error. Please explain also why?

Regards

Upvotes: 2

Views: 7649

Answers (2)

Vikash Pandey
Vikash Pandey

Reputation: 5443

use loc as a string...

var loc = window.location.toString();
alert(loc);
var fltURI=loc.substr(loc.indexOf("hey?hi=")+7, loc.length);
alert(fltURI);

Upvotes: 0

Shahar Bental
Shahar Bental

Reputation: 1001

window.location is a Location object, and not a string

Try:

var loc = window.location.toString();
var fltURI=loc.substr(loc.indexOf("hey?hi=")+7, loc.length);
alert(fltURI);

Upvotes: 4

Related Questions