0

I have a script which is using this line as part of some geocoding.

var dms = String(dmsStr).trim().replace(/^-/,'').replace(/[NSEW]$/i,'').split(/[^0-9.,]+/);

It works fine in all browsers apart from IE, which is kicking out an error.

I'm sending it parameters.

0.5501039994056782

It's not my code I'm just debugging it. I'm assuming it could be a problem with Typecasting it to a string, given that it's clearly a number.

But I'd love some feedback.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
David
  • 34,836
  • 11
  • 47
  • 77
  • 2
    *"which is kicking out an error..."* ***What*** error?! – T.J. Crowder Nov 01 '11 at 15:05
  • Comments below worked a treat. – David Nov 01 '11 at 15:30
  • Check this for further info though. Great answer worked a treat. Got stuck further down the line now. If anybody feels like being extra help, check this url for help diagnosing the next problem. client.bytewire.co.uk/marblesolar/roof-calculator What you should see happen is a directional line being drawn on the google map. See other browsers for test. IE reports a failure in jQuery and then due to that fails to pass correct data. – David Nov 01 '11 at 15:31

3 Answers3

3

There is no String.trim() in IE8. You can add it like this:

if(typeof String.prototype.trim !== 'function') {
  String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, ''); 
  }
}

as per this answer.

Community
  • 1
  • 1
karim79
  • 339,989
  • 67
  • 413
  • 406
  • Great answer worked a treat. Got stuck further down the line now. If anybody feels like being extra help, check this url for help diagnosing the next problem. http://client.bytewire.co.uk/marblesolar/roof-calculator/ What you should see happen is a directional line being drawn on the google map. See other browsers for test. IE reports a failure in jQuery and then due to that fails to pass correct data. – David Nov 01 '11 at 15:28
0

I don't think IE has trim(). Try this:

if(typeof String.prototype.trim !== 'function') {
  String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, ''); 
  }
}

See this SO question for more information

Community
  • 1
  • 1
Brad Christie
  • 100,477
  • 16
  • 156
  • 200
0

the exact error is

"Object doesn't support property or method 'trim'" 

so to solve you could do:

var dms = jQuery.trim(String(dmsStr)).replace(/^-/,'').replace(/[NSEW]$/i,'').split(/[^0-9.,]+/); 
Manuel van Rijn
  • 10,170
  • 1
  • 29
  • 52