javascript - str.indexOf is not a function error? - Stack Overflow

Simple, I'm doing this:var loc = window.location;var fltURI=loc.substr(loc.indexOf("hey?hi=&

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

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

Share Improve this question asked Mar 5, 2017 at 18:40 WjNaWjNa 894 silver badges8 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

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);

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);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745115858a4612123.html

相关推荐

  • javascript - str.indexOf is not a function error? - Stack Overflow

    Simple, I'm doing this:var loc = window.location;var fltURI=loc.substr(loc.indexOf("hey?hi=&

    8小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信