user583126
user583126

Reputation: 701

show popup during page load

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.

Upvotes: 0

Views: 2020

Answers (3)

Håvard
Håvard

Reputation: 10080

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.

Upvotes: 0

Chris Salij
Chris Salij

Reputation: 3126

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>

Upvotes: 0

Dancrumb
Dancrumb

Reputation: 27529

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.

Upvotes: 1

Related Questions