SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru
    Join Date
    Jun 2009
    Posts
    820
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    weird error -- getting only in Chrome....

    error:

    Uncaught TypeError: Cannot call method 'indexOf' of null (repeated 3 times)


    I'm getting this error only in Chrome, not even Safari... (and not FF..... don't know about IE, can't test on IE now...)

    what is this... I have never seen this before... (this error has to do with method indexOf(), but my use of it here is very conventional.... for example....

    Code:
    if (loc.indexOf('localhost') != -1) {
       .......
    }

    so what is this error....

    thank you...

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,941
    Mentioned
    215 Post(s)
    Tagged
    12 Thread(s)
    Hi there,

    Can you post a link to a page where I can see this error?

  3. #3
    SitePoint Guru
    Join Date
    Jun 2009
    Posts
    820
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    now it's doing something different...

    now when I press "submit" on the form the window is dimmed and it says "paused in debugger"... this only occurs in Chrome....

    I'm not sure I can post a url....

    why does Chrome do this... (also Chrome has a hard time refreshing updated .js files.. I once heard Chrome compiles javascript files.. I don't know what the purpose of this is, but it's not a very good idea if it doesn't always update the src code and recompiles it every time it changes...;-)

  4. #4
    SitePoint Guru
    Join Date
    Jun 2009
    Posts
    820
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    ok, that was a setting in Chrome Dev tools ("mouse" was turned on under "breaking points" don't know when that changed...)

    it's back to same error I was having before... I can't post a url, but here's a screenshot, I hope it helps to see the problem...

    the email gets sent, but b/c of error in "success" function the "thank you" part doesn't print...

    this line

    Code:
    if (loc.indexOf('resume') != -1) {
    var 'loc' is null ONLY IN CHROME.... how can this be? in FF it's fine...



    Code:
    function Success() {
    
    	console.log('loc success -- ' + loc);
    	........
    }
    prints fine in FF, it prints current url, in Chrome it prints 'null'......


    ??????

    thank you..


    PS: Chrome has a real problem updating JS files too... this is a huge pain.. yes we can do ctrl-F5... but.... are we supposed to put a note on pages for users that if you're in Chrome that's how you have to reload the page if it's not working??? ;-) I don't get why Chrome does this..

  5. #5
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,941
    Mentioned
    215 Post(s)
    Tagged
    12 Thread(s)
    Hi there,

    Quote Originally Posted by maya90 View Post
    var 'loc' is null ONLY IN CHROME.... how can this be? in FF it's fine...
    It's really hard to say without seeing the page.
    I can't really deduce anything from the screen shot.
    Sorry.

    Quote Originally Posted by maya90 View Post
    PS: Chrome has a real problem updating JS files too... this is a huge pain..
    One way around this is to add a ?<version> to the script src link:

    HTML Code:
    <script type="text/javascript" src="myfile.js?123"></script>
    See here for other suggestions: http://stackoverflow.com/questions/8...ng-my-js-files

  6. #6
    SitePoint Guru
    Join Date
    Jun 2009
    Posts
    820
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    thank you... I fixed it but the prob was really weird.... (and the fix is weird too..)

    this is what my prob was...
    http://stackoverflow.com/questions/7...luded-js-files

    i.e., in Chrome only, a global variable was not available inside a function, so I had to decl it again inside the fn.. very very weird.....

    thank you....

  7. #7
    SitePoint Guru
    Join Date
    Jun 2009
    Posts
    820
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Pullo View Post

    HTML Code:
    <script type="text/javascript" src="myfile.js?123"></script>
    how does this force it to update the js code? (and, in Chrome's case, compile again from newly-updated js code?)

    thank you....

  8. #8
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,941
    Mentioned
    215 Post(s)
    Tagged
    12 Thread(s)
    Hi there,

    Quote Originally Posted by maya90 View Post
    in Chrome only, a global variable was not available inside a function, so I had to decl it again inside the fn.. very very weird.....
    That is weird, I've not heard of that before.
    For example the following will work as expected in Chrome (where message is a global variable):

    Code JavaScript:
    var message = "Hello!";
    function sayHello(){
      alert(message);
    }
    sayHello();

    I'm guessing you had quite a bit more going on on your page.
    At least you got it sorted now

    Quote Originally Posted by maya90 View Post
    how does this force it to update the js code? (and, in Chrome's case, compile again from newly-updated js code?)
    You increment the version number and Chrome will recognize it as a new file and re-load it from the server.

    E.g. You have this:

    HTML Code:
    <script type="text/javascript" src="myfile.js?123"></script>
    and you update myfile.js.
    For whatever reason Chrome decides that it can use its cached version of myfile.js, so doesn't load the new version of the file.
    But if you change the query string, e.g.

    HTML Code:
    <script type="text/javascript" src="myfile.js?124"></script>
    then Chrome will reload the file without any further prompting.

    Hope that helps.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •