Solved

Remove CANCEL option from javascript window

Posted on 2008-10-16
3
195 Views
Last Modified: 2011-10-19
How can I modify this basic javascript script to remove the Cancel button which always displays in both MSIE and FIREFOX, along with the OK button. It may be there is no way, or not even a better way but I'd like to know for sure.

I want to show the user a window that does not give any sound such as ALERT, and avoid a nasty popup warning to the user. I do not want to open another window. This has to be simple as that's why I chose this mehtod.

This code below works fine, it just has the unnecessary CANCEL button. Displaying both OK and CANCEL does not make any sense for what I want. Actually, I'd also prefer an EXIT button but the OK button is okay. But the main point of this question is the CANCEL button.

Or can you give me better imroved code to do what I need?

<script language="JavaScript">
<!--
function javascript_lucky_help() {
	
var message = "Message goes here.";
 
  var return_value = confirm(message);
  if (return_value == true) {
	}
}
 
// -->
</script>
 
 
<div onclick="javascript_lucky_help()">
<input type="button" value="How This Works" />
</div>

Open in new window

0
Comment
Question by:Janrow
3 Comments
 
LVL 19

Accepted Solution

by:
LordOfPorts earned 500 total points
ID: 22737128
It is unfortunately not possible to customize the built-in confirm prompt and since you do not want to use alert or open a new window one other technique would be to use a fixed, initially invisible DIV that would be shows on click by switching its class. Here is one example where by a screenshot of an empty MessageBox which you can create in any development environment or custom draw an image is used as the background for a DIV and it is made visible on click.

Simply save the HTML code as test.html and the image as customconfirm.png in the same directory to see the example of this technique.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Custom Confirm</title>
    
    <style type="text/css">
        
        .CVisible
        {
            display: block;
            position: absolute;
            top:30%;
            left:40%;
            width:200px;
            height:126px;
            background-image:url('customconfirm.png');
        }
        
        .CInvisible
        {
            display:none;
        }
        
        #divMessage
        {
            position: absolute;
            top:32%;
            left:30%;
            font-size:12px;
        }
    
    </style>
</head>
<body>
<script type="text/javascript" language="JavaScript">
// <!--
 
function javascript_lucky_help() 
{ 
    document.getElementById('divCustomConfirm').className = "CVisible";
}
 
// -->
</script>
 
 
<div onclick="javascript_lucky_help()">
<input type="button" value="How This Works" />
</div>
<div id="divCustomConfirm" class="CInvisible" onclick="this.className='CInvisible';">
 <div id="divMessage">Message goes here.</div>
</div>
</body>
</html>

Open in new window

customconfirm.png
0
 
LVL 44

Expert Comment

by:scrathcyboy
ID: 22737287
Even in a subwindow, you cannot get rid of the square - bar to minimize, and X to close window.  If you could, there would be no way for the user to get rid of the window.
0
 

Author Closing Comment

by:Janrow
ID: 31507002
Yes, that gives me plenty of options and I believe will let me do what I want. Thanks so much!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question