2

I'm processing something and when the function is successful I would like to redirect to another page and there show the alert "Function successful".

I'm using CodeIgniter, Javascript and Bootstrap

Any ideas will be appreciated

jonathanwiesel
  • 1,036
  • 2
  • 16
  • 35

2 Answers2

2

Once page X has redirected to page Y, page X is no longer open, so can no longer issue alerts. Your options include:

  • don't redirect. (Instead, you may be able to put page Y in an iframe; or, simply provide a link to it and let the user decide whether to click.)
  • don't alert.
  • alert before redirecting. (This is basically the same thing. The user can't actually interact with page Y until they've closed the alert, anyway, so it doesn't really matter whether the alert comes before or the redirect or after it.)
  • have page Y give the alert. For example, page X can redirect to http://example.com/path/to/Y/?alert=Function+successful, and you can design page Y to detect the query string and issue the alert.
ruakh
  • 175,680
  • 26
  • 273
  • 307
  • Using codeigniters flashdata sessions are also an option : http://ellislab.com/codeigniter/user-guide/libraries/sessions.html – Jeemusu Jan 30 '13 at 02:46
1

When the functions is successful, redirect and use the body onload event of the new page. Using a querystring extraction based on another SO answer:

if (success)
{
window.location("anotherpage.html?myparm=alertMe");
}

...

anotherpage.html

<body onload="bodyLoad();">
...
</body>

<script type="text/javascript">
function bodyLoad()
{
  parmValue = getParameterByName("myparm");
  if(parmValue == 'alertMe')
  {
    alert('Function successful');
  }
}

//http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values
function getParameterByName(name) {
    var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
    return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}
</script>
amelvin
  • 8,919
  • 4
  • 38
  • 59