0

i have a requirement to show javascript Ok/Cancel option on page load. So, when the user is redirected from the previous page to this page, based on some logic in the query string, we have to display javascript OK/Cancel (page is not yet rendered here). Once the user clicks, we have to load different type of data (server side execution) based on OK/Cancel. what is the best way of accomplishing this task? thanks.

user583126
  • 681
  • 1
  • 9
  • 21
  • 1
    What happens if the user has Javascript disabled? – Dancrumb Mar 30 '11 at 19:20
  • Good point Dan. instead of the OK/Cancel stuff, have you (user583126) considered a < noscript > solution? – Andbdrew Mar 30 '11 at 19:22
  • @Andbdrew: What is the – user583126 Mar 30 '11 at 19:26
  • @user583126 – Dancrumb Mar 30 '11 at 19:27
  • @user583126 html inside a – Andbdrew Mar 30 '11 at 19:29
  • ok, I understood the noscript thing. But how do i accomplish my task. Let's assume that JS is always enabled! – user583126 Mar 30 '11 at 19:33

3 Answers3

1

Ignoring the various problems with this requirement, here's the simplest approach that I can think of.

  1. Create an HTML page with no content
  2. Execute the following in Javascript:

    1. Grab and parse the querystring
    2. Based on the querystring, determine which URL you would like to redirect the user to
    3. Use confirm() to determine the course of action
    4. Change the window location to your new page

Your <noscript> element should contain directions on what a user who has javascript disabled should do... something more helpful than 'Please enable javascript' would be nice, but it's your call.

Community
  • 1
  • 1
Dancrumb
  • 26,597
  • 10
  • 74
  • 130
0

Load a small html page stub with basic formatting, then popup your dialog box.

Depending on the response, populate the page's contents using an ajax request.

Here's some very basic example code. See this tutorial for examples of how to make an Ajax call in javascript.

<html>
  <head><!-- Head Contents --></head>
  <body>
    <!-- Basic body styling -->

    <noscript>This page works best with scripts enabled</noscript>

    <script type="text/javascript">
      // Show Dialog Box
      if(option1) {
        // Do Ajax call
        // Set page contents 
      } elsif (option2) {
        // Do other ajax call
        // Set page contents 
      }
    </script>
  </body>
</html>
Chris Salij
  • 3,096
  • 5
  • 26
  • 43
0

Vanilla popping up a dialog:

if (confirm("Your question")) 
{ 
    // do things if OK
}

Although you should look into the other answers/comments here, as this will break if the user has disabled javascript.

Edit: If you want to load more info after the dialog, you will have to use ajax. Since your answer is quite general, I can only point you in the direction of the jQuery ajax functions for now.

Håvard
  • 9,900
  • 1
  • 41
  • 46
  • this will execute after your server side events are all executed for the page! I am looking for page events to continue execution after 'something' has happened on the client side. – user583126 Mar 30 '11 at 19:38
  • Then you'd have to use ajax to fetch more info after the dialog. I'll edit the answer to add some information on this. – Håvard Mar 30 '11 at 20:42