Customize Javascript Alert NOT onclick - javascript

I have absolutely no idea about Javascript and don't know if it is even possible. Anyway, I found a script that customizes Javascript Alert Box. It works nicely. The issue I am having is that this customization works based on 'onClick' as below:
// Standard Dialogs
$("#alert").on( 'click', function () {
reset();
alertify.alert("This is an alert dialog");
return false;
});
However, my Alert Box is generated by different code, and it either generates Alert Box or redirects to another page, but has nothing to do with onClick function. My question is:
is it possible to customize the Alert Box which is generated outside of the onClick function? If so, could anyone let me know how?
And my sincere apologies if that subject was already explained somewhere - I was looking for an answer but could not find.
Thank you

If you're trying to have the alert pop up initially without prompt it appears you will need:
alertify.alert("This is an alert dialog");
to be pasted outside of the function.
This will trigger the alert when the page loads as long as your tags are at the bottom of your html &/or you've used a document.ready statement.
My other interpretation of your above message is that the code above works and another alert box doesn't in which case can you please show us the code from the code that is not displaying as customised.

Related

How can I make a function to program Chrome to set itself the "Break" status at my workplace

I am working in a call center, and everytime i go to the toilet, I have to change my status to "Break" using a dropdown menu from the google chrome page(internal website).
I can use inspect and see all the classes and button ids but for some reasons it's not working, it give me the error "undefined".
function Myfunc (){
var button1 = document.getElementById("_10erop07");
button1.click();
}
How Can i make a script, that at a certain hour, I enter code here will automatically trigger at the certain hour.
Basically, I want the script to click on the dropdown and select the "Break" status.
Any ideas how can I do that?
This can easily be done using Bookmarklets
follow the steps in the guide link above.
your javascript code should look something like this
javascript:(
function(){
// YOUR CODE SHOULD BE HERE
}
)();
But make sure to click the bookmarklet when you are in the website
I hope that helps.

What is best way to make sure alert box doesnt pop up if an alert is already there?

In javascript, if I have an infinite loop:
setInterval("popalert", 5000)
Where popalert() simply pops an alert box, what is the best way to make it such that an alert box does not pop up if there is already a single alert box that has not been closed yet?
There is no way to detect that the alert is there.
Do not use setInterval, use setTimeout.
Reset the timeout after the alert happens.
jsfiddle example
It's impossible to detect the standard javascript alert boxes as they are extremely simple. If you keep spawning them they will just queue and in modern browsers it actually gives you the option to suppress them for a certain page after a few.
I would consider using a different type notification system if having no more than 1 box at any time is important to you. Something like jQuery UI Dialog.
The popalert function could save the state of the alert box.
var bOpen = false;
then when its poped up set it true
and if it closes after pushing ok or something set it false again.
when popalert is called again it checks the bOpen var and if its true, it just doesn't open a new popup.
also I would use settimeout, so you don't get this endless loop stuff blocking your gui.
You can't detect if an alert box is already here.
Your navigator manage this alert box, so they can't popup if another is already here.
You can use a global javascript variable (out of any function) and set this var initially to false. If your popalert function is called, check if the global var is false. If so, pop your alert and set the var to true. Doing this only one alert will be shown, but your function will be executed again and again (if this is important).

Javascript alert popup form

i have search this whole site and google but cannot find it so, here goes!
i would like a way to show a form when using alert.
for example, when user click post, a dialog pop with asking user a few question like a html form and allow user to click submit or reset or cancel, without loading a new page.
i have seen this done but cannot find the same site again.
i have tried putting htm to alert with little success of posting.
any Help is Highly Appreciated!
What you are looking for is a Prompt Box:
<script type="text/javascript">
function show_prompt() {
var name = prompt('Please enter your name','Poppy');
if (name != null && name != "") {
alert(name);
}
}
</script>
example taken from here: http://www.w3schools.com/js/js_popup.asp
you can do this with jQuery dialogs -- load the dialog on user click and have a form presented in the dialog. have a look at the demos here: http://jqueryui.com/demos/dialog/
To complete #Liv's answer you can use jQuery's UI
Reference: Modal Form
The example shows how to create a new user. It will pop up a dialog where you complete a form and you can submit it or you can cancel it.
Use a modal dialog to require that the user enter data during a multi-step process. Embed form markup in the content area, set the modal option to true, and specify primary and secondary user actions with the buttons option.
It pretty much what I understood you need.
Good luck!
HTML can't be placed in system dialogs generated by alert(), confirm() or prompt(). However, you can download jQuery UI and set it up on your Website. (Make sure you have the "dialog" component chosen on the download page.) Then in your JavaScript:
$("<div>Place your HTML here</div>").appendTo("body").dialog({
modal: true,
title: "Enter a title here"
});
Make sure you run this code after the page has loaded by using either window.onload or $(document).ready().
Ad#m
You will not be able to do this with alert, but you should take a look at how to create modal windows.
I recommend you to use a div popup. What you have to do is setting a background on top of all other elements except the div where your form is. The css property display will be set to 'none' until the form is then activated, by setting display = "block". That can be performed using javascript.

Alert Box error

I have alert boxes all around my site, that have been working up until now, ( I have done a few updates to my blog recently before this started happening ) the problem I am experienceing is that when I click on a link ( in my case a image link ) and the alert box appears, I submitt the ok button and suddenly im rediercted to a white page with 'true' in the top corner. My alert box scripts are inside my blog template.
I tested this alert box script out in a blog post:
<"a href="javascript:onClick=alert("Not an active link");">CLICK<"/a>
withouth the extra "
and then went to preview the post, however the same error occured. This is not a browser problem as it only happens on my site, when i got to someone elses with alert boxes, it works. Please help with this I have been asking about it for about a week now and would appreciate someone who can help
here is a screenshot of what I get redirected to:
http://img813.imageshack.us/img813/2674/true.png
Thanks for all help.
Use this
CLICK
Demo here: http://jsfiddle.net/e2fkT/embedded/result/
I think you have some typos... It would be:
click
Use simple quotes inside or escape double quotes.
I don't understand the use of onclick there too... Just the alert will open an alert box when you click.
click
Also it would be better to separate javascript from html... You could include with the following content (jquery example, i forgot almost everything about old javascript... just get the idea) into a non-active-links.js file or in a block:
$(document).ready(function () {
$('a.non-active-link').click(function () {
window.alert('Not an active link');
return false;
});
});
That way all links in the page with a class attribute of "non-active-link" will fire up the alert box.
I think you messed up with javascript inside href and the onclick attribute. Your snippet is actually assigning the result of the alert function call to the variable onCLick. The display of true might be the return value of the alert method. Still an odd behavior.
CLICK
CLICK
Those two cause no problems to me.

How to block alert box through jQuery

I want to block alert box if it is present in code. Im using an api that tells me the search result of my website and if any user enter
<script>alert('Just teasing')</script>
then it shows an alert box on my page how can i stop this alert?
First of all you should sanitize you input as #Nikita commented.
If you want to accept JavaScript and only disable alert you can replace the window.alert function.
window.alert = function() { /* do nothing here */ }
Now calling alert won't do anything.
When presenting the search results back to the user you need to ensure you HTML encode the output so the user would see the script rather than it being executed.

Categories

Resources