Alert after page load

asp.net-mvc, html, javascript

Solution

If you can use jquery then you can put the alert inside the `$(document).ready()` function. it would look something like this:

<script>
  $(document).ready(function(){
    alert('<%: TempData["Resultat"]%>');
  });
</script>

To include jQuery, include the following in the `<head>` tag of your code:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>

Here's a quick example in jsFiddle: http://jsfiddle.net/ChaseWest/3AaAx/

Problem

This is my script : ``` <% if (TempData["Resultat"] != null){ %> <script type="text/javascript"> alert('<%: TempData["Resultat"]%>'); </script> <% } %> ``` In this case pop-up is shown before page loaded, but i want that's appear after page is fully loaded. in Html it's looks like this : ``` <body onload="happycode() ;"> ``` but i can't use it in MVC i got one master page for all my web application

Original source

Related problems