Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error on using alert in Javascript (Property 'alert' of object is not a function)

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.

like image 722
Idan Shechter Avatar asked Jul 04 '12 19:07

Idan Shechter


People also ask

Why alert is not working in JavaScript?

The reason alert() does not work is because previously you have checked "prevent this page from creating additional dialoug" checkbox. lets take a look at this code. There will be two alert boxes if you run the code.

How do you solve the is not a function error in JavaScript?

The TypeError: "x" is not a function can be fixed using the following suggestions: Paying attention to detail in code and minimizing typos. Importing the correct and relevant script libraries used in code. Making sure the called property of an object is actually a function.

Which object has alert () method?

The alert() is a method of the window object.

Which object as alert method in JavaScript?

The alert() method is used to show an alert box on the browser window with some message or warning. We can use it as a message or as a warning for the user. Approach: To show an alert on the browser window, we make a button.


1 Answers

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.

like image 178
Chris Laplante Avatar answered Sep 18 '22 17:09

Chris Laplante