Any one please help me in controlling the "X" (cancel Button) of alert box in edge browser, Either i have to remove it or i have to get the click event.
By a native dialog-boxes it isn't possible.
Other site you don't need it because the OK button has the same function like the close button in this dialog-box: in both ways the dialog-box will be closed and nothing else.
But if you want to control it you can create your own alert dialog-box. Or you can use some library or framework with custom dialog-boxes.
Related
When I am on IE, when I use tab to move my focus to the link and press CTRL+Shift+Enter, I get the page opened in another tab. I want to restrict this behavior on IE and show the message to user like "not supported", please suggest me how to achieve this using javascript.
You can try using keystroke events. On keystroke, alert the user & return false.
Reference :
Disable Shortkeys when Ctrl or Shift clicked`
I have clicked many buttons without ever hitting a problem like this. I'm using VB 2010. If I click on the control programmatically or manually, the screen flashes like it is just refreshing. However, if I open a separate IE window, I can click the button and it advances to another screen as expected. I have researched this on other sites and have found one suggestion that the control is using a different version than the full version, which is IE 8 in my case. This still doesn't provide a solution. Can anyone please help? Here is the code which clicks the button as well as the html of the button.
WebBrowser1.Document.All("posForm:estimate").InvokeMember("click")
<button onclick="validateForEstimate(this, 'NonITS');" type="button" name="getestiamte"></button>
Maybe try the Microsoft Browser go to your toolbox right click and click choose items then go to COM components and use the filter to find Microsoft browser then check mark it. Add it to your form and done.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Javascript close alert box
A confirm box can be opened by,
confirm("Sure?");
which opens a confirm pop up with two buttons- OK and Cancel.
The pop up closes when either of the two buttons are clicked. How can we close the pop up without clicking the buttons, pragmatically? Can we trigger the event which closes the pop up using JavaScript?
Short answer: No.
Long answer: The three DOM0 windows of alert, confirm and prompt are modal windows. The browser (or the browser window, depending) freezes when those using one of those input methods and nothing Javascript-wise happens.
The only thing you can do is to create a popup DIV with your own confirm buttons and give your popup window callback methods on what to do on confirm accept and cancel.
A setTimeout could be used to auto-close the window after a pause.
No, because that function is blocking the browser. No JavaScript code will run during the time while it is open - not even scheduled timeouts and other event handlers.
See window.confirm on developer.mozilla.org.
For an example of something that acts in a way that you want, see this example of the jQuery UI library.
You can only achieve this by creating your own Confirmation box using Modal popup and setting the setTimeout() or setInterval() against it.
or try this if it helps....http://cool-javascripts.com/effects/jgrowl-to-show-unobtrusive-messages.html
Right, I've edited this post a bit following some further tests I've been doing, my original post is below, however, this is now the crux of the issue.
I have 3 images on a page, when one is clicked a javascript window.confirm dialog is displayed asking the user to confirm their selection. However, due to the positioning of the images on the page, the dialog appears over an image, when trying to click OK or Cancel, nothing appears to happen. However, what actually does happen is that another confirmation appears over the top of the original one, and this continues. However, if I click somewhere on the button that doesn't have the image behind, then it works, but only after double clicking.
What I've found is that when a dialog is displayed, it doesn't automatically get focus, so you have to click it to focus, before clicking the button again to close the dialog. If on the first click you click the part of a button (or the dialog itself) that has an image behind, that image is actually clicked as the dialog doesn't have focus. However, if you click anywhere in the dialog which doesn't have an image behind (therefore focusing on the dialog), then click OK or Cancel, it works (even where the OK or Cancel button has an image behind).
So what I need to know is, is there a way of automatically focussing on the dialog when it opens, therefore preventing the need for double-clicking? Or is this just a safari bug that I'll have to find another way around.
--------original post---------
I have a website with a series of images and links. When an image or link is clicked, a window.confirm dialog is displayed asking the user if they are sure they want to carry out the action.
In IE, Opera and Firefox this works fine.
However, in Safari, when I click the OK or Cancel buttons on the dialog, whatever is on the page behind the button is actually clicked, rather than the button in the dialog itself. The dialog actually says "Are you sure you want to vote for xyz", where xyz is based on the clicked image or link - when I click OK or cancel in the dialog the text changes to whatever image/link is behind that OK/Cancel button.
Has anyone seen this bug, and/or knows a way around it?
UPDATE
I've been managing to narrow it down a bit, and have just found where the issue seems to lie.
I found that if I clicked the part of a button that didn't have an image behind it (each image is actually a .NET ImageButton), then it would work (though it requires a double-click). If I click part of a button that does have an image behind it then it would open up a further alert/confirm dialog. I've put some JQuery in which adds a click event to each image, on clicking it hides the image, then displays the dialog, and the dialog works fine.
Obviously this isn't what I require (don't really want the images disappearing), but it has narrowed it down. Any ideas how this can be solved?
Another update: I think that actually the alert/confirm dialog isn't initially getting focus, hence the need to double click. If I click the dialog (anywhere where an image isn't behind) then click OK (even if there is an image behind that button) then it works. So, how do I get it to focus automatically on the dialog once its opened?
I just ran into this myself and haven't found an answer yet, but I thought I would post things I have observed to see if they're the same for you.
You say you have to click the dialog to give it focus before it will work. I have found that you simply have to click anywhere in Safari, even not on the dialog, and the dialog will start working. Furthermore, it doesn't seem to be exactly a focus issue as keyboard control of the dialog still works, Space to select OK, or Tab and Space to select Cancel. Can you confirm this?
What version of Safari are you running and what version of Windows? I am running Windows 7, Safari 5.0.3 (7533.19.4). I will try to test this on Mac as well or you could if it's convenient for you.
In Windows 7 buttons highlight on mouse over even if they are in a window without focus. This issue in Safari causes some interesting reactions in the buttons. When the dialog first pops up buttons on the page still highlight on mouse over, but the buttons in the dialog do not. After a click in Safari the Cancel button in the dialog highlights on mouse over, but the buttons on the page do not and the OK button in the dialog does not. However, if, instead of clicking in Safari, some other application is given focus by a click both buttons in the dialog highlight while the buttons on the page do not. There is even more inconsistent behaviour when Safari regains focus. If it regained focus by a click in the dialog both the buttons in the dialog highlight. If it regained focus by a click not in the dialog only the Cancel button highlights, not the OK button.
That was all if focus was transferred with the mouse. When focus is transferred by Alt-Tabbing there is different bahaviour. In that case when a different application is first given focus the buttons remain as they were with the buttons on the page highlighting and the buttons in the dialog not. If Safari is Alt-Tabbed back to it's as if nothing has happened and you still have to click to get the dialog working. If Safari is clicked on anywhere, in the dialog or not, both buttons in the dialog highlight and the buttons on the page do not.
Inconsistent behaviour of buttons can be found elsewhere in Safari. The Print and Save menu items bring up Windows default dialogs so buttons in those behave consistently with Windows. Safari specific dialogs, like the Javascript confirm, Customize Toolbar..., and Report Bugs to Apple... have different sized buttons. Furthermore, the Done button in Customize Toolbar is the default button, but will not highlight until the dialog has been clicked on. The Submit button in Report Bugs is the default button and will highlight on mouse over without clicking on the dialog, but does not show the blue ring to indicate it is default until it has been moused over.
All of this is, of course, what I experienced so it may not be the same for you. At this point, because the behaviour is so inconsistent I think it is a bug in Safari, but I will investigate further.
I was just about to report a bug myself. I have a confirm dialogue come up to request yes or no to delete an image from a gallery. This situation is performed in a popup window. Whether I click OK for true or cancel for false, the action closes the popup and thats it!
As mentioned from a previous post, if I go outside the dialogue and keep clear of any links, images or things that call javascript and click somewhere else in the popup window, go back to the dialogue, the dialogue buttons work. It seems like a focus issue. The dialogue also seems sort of transparent, clicking anywhere on it will effect anywhere underneath it as my case, I have images that when clicked on call a function.
I also encountered this problem, and this is how I resolve it.
setTimeout(function() {
var confirm = confirm("Are you sure you want to send it?");
if(confirm) {
// do stuff here
} else {
// do stuff here
}
},10);
this is quite inconvenient solution but at least it works without huge alteration and also works fine in other browsers too.
From my experience what is actually happening is the mouse clicks go thru the dialog box as if it is not there at all. If what is behind it happens to be the button that launches the dialog box you get stuck in a loop of one dialog after another coming up. I know this is nothing in my code since the same effect happens on other web sites. This is only a bug on Windows not on a Mac. I am using Safari 5.0.3 on Windows XP.
I want to be able to close an alert box automatically using Javascript after a certain amount of time or on a specific event (i.e. onkeypress). From my research, it doesn't look like that's possible with the built-in alert() function. Is there a way to override it and have control over the dialog box that it opens?
Also, I don't want an override that shows a hidden div as the alert. I need an actual dialog box.
As mentioned previously you really can't do this. You can do a modal dialog inside the window using a UI framework, or you can have a popup window, with a script that auto-closes after a timeout... each has a negative aspect. The modal window inside the browser won't create any notification if the window is minimized, and a programmatic (timer based) popup is likely to be blocked by modern browsers, and popup blockers.
Appears you can somewhat accomplish something similar with the Notification API. You can't control how long it stays visible (probably an OS preference of some kind--unless you specify requireInteraction true, then it stays up forever or until dismissed or until you close it), and it requires the user to click "allow notifications" (unfortunately) first, but here it is:
If you want it to close after 1s (all OS's leave it open 1s at least):
var notification = new Notification("Hi there!", {body: "some text"});
setTimeout(function() {notification.close()}, 1000);
If you wanted to show it longer than the "default" you could bind to the onclose callback and show another repeat notification I suppose, to replace it.
Ref: inspired by this answer, though that answer doesn't work in modern Chrome anymore, but the Notification API does.
no control over the dialog box, if you had control over the dialog box you could write obtrusive javascript code. (Its is not a good idea to use alert for anything except debugging)
I want to be able to close an alert
box automatically using javascript
after a certain amount of time or on a
specific event (i.e. onkeypress)
A sidenote: if you have an Alert("data"), you won't be able to keep code running in background (AFAIK)... . the dialog box is a modal window, so you can't lose focus too. So you won't have any keypress or timer running...
Try boot box plugin.
var alert = bootbox.alert('Massage')
alert.show();
setTimeout(function(){alert.modal('hide'); }, 4000);
I guess you could open a popup window and call that a dialog box. I'm unsure of the details, but I'm pretty sure you can close a window programmatically that you opened from javascript. Would this suffice?
The only real alternative here is to use some sort of custom widget with a modal option. Have a look at jQuery UI for an example of a dialog with these features. Similar things exist in just about every JS framework you can mention.
If you do it programmatically in JS it will be like reinventing the wheel. I recommend using a jQuery plugin called jGrowl
You actually can do this you can basically listen for this pop up to happen and then confirm true before it ever "pops up",
if(window.alert){
return true
}
You can use label and set its fade in and out time for e.g
Hide it initially and show on click.
$('#div_Message').fadeIn(500).delay(1000).fadeOut(1500);
window.setTimeout('alert("Message goes here");window.close();', 5000);