Replace alert/prompt/confirm in unicode environment!

H

Hans

Hi!

I have an asp application where I use a lot of javascript for validations
etc and as it is today I use alert, confirm and prompt dialogs. Now we are
adding support for unicode and I have problems with the font used to present
messages in alert, prompts and confirm dialogs. If I for examle paste a
chinese value in a prompt dialog it is shown om my machine as a vertical
bar. When I write the value back to a textbox <input type="text" the correct
chinese character is shown. The problem seems to be the font used in the
dialogs. I tried to change the font but could not get this to work.

So I'm looking to create my own dialogs replacing the alert/prompt/confirm.
Alerts can be replaced by either a popup window presenting the text in pure
html (a bit slow because of roundtrip to server) or a message could be
presented using dhtml (div or span). I have harder to fix the confirm/prompt
where I'm expecting a return value.

I have to support IE5.5sp2 and higher and also Netscape 7+ so I cannot use
the IE specific showModalDialog.

Any example how to solve this would be great!

Regards
/Hans
 
G

Grant Wagner

Hans said:
Hi!

So I'm looking to create my own dialogs replacing the
alert/prompt/confirm.
Alerts can be replaced by either a popup window presenting the text in
pure
html (a bit slow because of roundtrip to server) or a message could be
presented using dhtml (div or span). I have harder to fix the
confirm/prompt
where I'm expecting a return value.

You can open a new window and display "custom" content without making a
trip to the server. Let me say this is a completely contrived example,
your definition of morning, afternoon, evening and night may be
completely different, the time and/or time zone on the visitor's system
may be incorrect, etc. It is just an example of how to display dynamic
content without resorting to a trip to the server:

<script type="text/javascript">
var now = new Date();
var hours = now.getHours();
var greeting = 'Good ';
if (hours < 12)
{
greeting += 'morning';
}
else if (hours < 18)
{
greeting += 'afternoon';
}
else if (hours < 20)
{
greeting += 'evening';
}
else
{
greeting += 'night';
}
window.newWindowHtml = [
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">',
'<html>',
'<head>',
'<title>Untitled</title>',
'</head>',
'<body>',
greeting,
'</body>',
'</html>'
].join('\n');
var w = window.open(
'javascript:eek:pener.newWindowHtml',
'windowName',
'...attributes...'
);
Any example how to solve this would be great!

As long as this is an Intranet (or otherwise controlled environment)
where you can _guarantee_ your users will always have JavaScript enabled
and will always allow popups, you can use windows created with
window.open() to create custom prompts and obtain feedback.
 
H

Hans

Hi Grant and thanks for the answer!



This is an intranet environment and I know for sure javascript is enabled.



The code I have today (as I said) uses for example prompt, confirm and I
want to make as few changes in the code as possible to remove the use of
those functions. For example I use confirm when a user tries to delete a
record.



if (confirm("Delete record"))

//do the actual delete

else

//do nothing or whatever is supposed to happen when the user is pressing
cancel.



One of the problems I have removing the confirm here is that a confirm is
waiting for an answer. If I open a new window how can I do this and stop
executing the actual delete until the user presses yes in the opened window?
The only solution I found was to split this into two functions. One that is
called when the user wants to delete a record. This function will open a new
window asking if he/she really wants to delete the record and if they press
yes I call another function in the opener window that do the actual delete.



Another solution I was looking at was to show a <div> with OK/cancel buttons
in it but the problem I have here is that I want the div to show up where
the user clicks on the delete button and I have problems with IE and
<select> tags where <div> are put behind the dropdown list. Since the
arrangement of fields is very flexible in the system dropdowns, edit boxes
etc may be placed almost anywhere so I cannot find a place to show the <div>
and be 100% sure it will not be behind a dropdown list.



Regards

/Hans
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top