14

I am just trying to use alert and put a string variable inside the alert and get an error:

Uncaught TypeError: Property 'alert' of object [Object Window] is not a function

My code is:

var shortenurl = msg.d;
alert(shortenurl);

I've checked the value and it has a string inside, not an object.

Liron Harel
  • 10,819
  • 26
  • 118
  • 217

7 Answers7

45

Somewhere in your code you overrode alert. Check for var alert = ... or some other kind of declaration like that. Also check for window.alert declarations.

Chris Laplante
  • 29,338
  • 17
  • 103
  • 134
23

I had that error message due to an alert() blocked by my pop-up-blocker.

Lester
  • 1,830
  • 1
  • 27
  • 44
6

I'm adding this one as an addition to this. In my case, when I had a similar problem, it turned out to not be my own code that was causing the problem but a poorly written extension that had been added to a client's browser. Once it was disabled, the script error went away.

If you haven't overridden the method name in your own code anywhere, you may want to try disabling extensions to see if any of those is inadvertently interfering with your script.

Rob Wilkins
  • 1,650
  • 2
  • 16
  • 20
  • Yeah that was my problem too. In Chrome, Ctrl+Shift+N to jump into an incognito window. Run a test in there. Also, if this is the case, you'll notice that alert() fails on every site, not just what you're working on. – Ev. Apr 19 '13 at 05:15
  • Yeah, i had a popup blocker, which was disabling alerts. I disabled that extension in chrome and now it works fine – Nanu Jul 11 '13 at 19:54
4

Check if you've got a Bootstrap .js declaration if required (after jQuery) i.e.

<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
WojCup
  • 83
  • 4
1

Adding to Chris's answer... I had mistakenly overrode alert in my own function!

    //Don't do this:
    function alertOrConsole(node, alert){
        if(alert){
            alert(node);
        }else{
            console.log(node);
        }
    }

   //----------------------------
   //Fixed:
    function alertOrConsole(node, flag){
        if(flag){
            alert(node);
        }else{
            console.log(node);
        }
    }
Petro
  • 3,484
  • 3
  • 32
  • 59
1

One of the possible reasons could be that alert is used as variable - for example inside of function:

function MyFunction(v1,alert) { alert(v1); //will fail exactly with that message }

Solution is not to use predefined words as variables.

0

Mozilla says,

The alert function is not actually a part of JavaScript itself.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript

You can not see a function called alert here : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects

smilyface
  • 5,021
  • 8
  • 41
  • 57