homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Modal Dialog Killer

10+ Year Member

Msg#: 4525855 posted 10:59 am on Dec 7, 2012 (gmt 0)

Hello All -

I'm still pretty new at javascript but I've got a few functions that are working pretty well with one exception.

Here's the scenario:

1. User deletes an item from a page.

2. javascript function deletes the target item from the database and then reloads the remaining items from the same table.

3. a modal dialog appears notifying the user that the item has been successfully deleted. The user must click the "OK" button on the modal for it to dismiss.

All of the above works fine, except when...

The user deletes the LAST ITEM on a page window.location.href take the user to another page.

Under this circumstance, the:

- Item is deleted
- User is automatically re-directed
- Modal appears, but disappears within a few seconds without the user needing to click the ok button.

What is appearing to happen is that window.location.href is still happening when the modal is fired... but what's weird is that window.location is called BEFORE the model is called.

The actual code-calls are here:

// Redirect if needed
if(data.redirect) window.location.href = data.redirect;

// Display remaining data from database
if(data.content) {

// Fire confirmation modal dialog

Anyone got any idea on how to (if this is even the problem) make sure the re-direct has completed BEFORE the modal is called.

All guidance gratefully appreciated!



WebmasterWorld Senior Member drdoc us a WebmasterWorld Top Contributor of All Time 10+ Year Member

Msg#: 4525855 posted 6:36 pm on Dec 7, 2012 (gmt 0)

The problem is that the JavaScript code completes much faster than the browser takes to redirect.

A very simple fix is to make your code a complete
if...else statement:

if (data.redirect) { 
window.location.href = data.redirect;
} else {
if (data.content) {

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved