can we have anchors in alerts? - javascript

I want to throw an alert message if a user enters a bad username/password and give users an option to hit "ok" which lets them try the page again or "forgot password" which lets them go to a different link to change their password.
Can I use an alert box and add an anchor to it ? I don't want to have a button floating around until someone enters a wrong password.

No. alert() boxes can only display plain text. If you wanted to create your own pop-up box like that you would need to implement it yourself, you couldn't use alert().

You may want to use confirm().
This function shows a message followed by a Ok and Cancel buttons:
if (confirm('You used a wrong password; Would you like to retrieve your password ?')) {
document.location = 'retrieve the password';
}

The built-in alert function won't show hypertext, just text. You can use a fancier implementation from any one of the popular Javascript gui libraries. They will let you create an HTML pop-up instead.

alert does not display HTML. You'll have to emit markup to display the message instead. There are many libraries that can do this for you, including jQuery UI.

That's not possible. You can use the showModalDialog function instead. See the demo at this page.

No, you will have to show the user a custom message. You may want to use absolutely positioned DIV element, a modal dialog window or an iframe for that purpose.

Related

JavaScript interactive form in alert box?

Is it possible to put a form into an alert box and then display that to the user? Afterwards I would want to submit the data but I presume it would work the same via a 'POST' method or such.
I had a quick play around but couldn't get it to work, not much on search engines either.
Thanks for any help!
An alert box is not editable. You can use javascript to create a new browser window with your form in it.
General form is like this: window.open('url to open','window name')
You will fall foul of popup blockers if you handle 'when' you do this badly.
This is quite a nice simple walk through with live examples http://www.pageresource.com/jscript/jwinopen.htm
You could use jQuery UI's dialog. This allows you to turn a DIV into a pop-up box.
I would recommend you jquery shadow: http://www.htmldrive.net/items/show/650/jQuery-Custom-PopUp-Window.html
Or if you want you can develop your own form (html, design, css, javascript).
If it's just a single input, you can use the built-in prompt() method.
Otherwise, you would have to pop up your own form.

Show custom message and button text for javascript confirm dialog?

Is it possible to give custom message for buttons instead of Cancel/Ok and give my own text?
I saw lots of tutorials on replacing js confirm with jquery dialog. But isn't there a way with using native JS? I see the same thing done in Grooveshark and many other pages; when user wants to navigate away from their page user is prompted with a js dialog box with custom buttons like 'Stay on page/Leave page'?
Any idea how they might be implementing this? Their dialog box appears as if generated using native JS!
I believe you were seeing a slightly different dialog box.
Add this to your page:
window.onbeforeunload = function() {
return "Are you sure you want to navigate away?";
}

Javascript Alert - Removing "The page at ??? Says"

I have a form and I am using Javascript to validate the form so if you leave a field blank it will alert "Please fill in your Name".
If I go to the link directly, it works perfectly. But this is kind of like a Widget so I am using an iFrame to embed it into other sites. When I embed it, and click Submit with an empty field it says: The page at http://www.example.com says: Please fill in your name
Is there a way to get rid of that?
No, there isn't. It is an anti-phishing feature.
If you want a dialog without it, then you have to fake it using HTML elements in your page.
For those who are still looking to use the native alert/confirm, it's not that hard to get past the anti-phishing implementation. This is because the iframe can edit the parent and access it's scope.
Try this:
parent._alert = new parent.Function("alert(arguments[0]);");
parent._alert('Test!');
The reason this works is because new Function('') does not create a closure and instead uses the scope of where Function is defined (via parent.Function).
You can use some custom alert plugin. For example http://stefangabos.ro/jquery/zebra-dialog/

Change name of alert in jscript

Is there a way to change the name of a alert dialog box in jscript, like instead of it saying ("Alert" "Message") can it say something like ("Hello" "Message") this is the script im using:
Click Here
Thanks :D
If you want to alias alert it would be:
var t = alert;
t('blah');
If you want to change the text of the alert box's title bar, you can not.
Not as far as I am aware with the default basic Javascript alert() dialog box.
In fact, different browsers will have different title bars on the dialog. Some have "Alert", others have "The page at http://someurl.com says:" and it goes on.
A far prettier, and more customisable option is to consider using something like jQuery UI. It has features like the dialog, which create a nicer, in-page dialog box with customisable buttons, title, and content.
It requires use of the jQuery library, which is a hugely popular Javascript library to greatly ease Javascript development, and plainly, make it more fun.
The best way to implement an alert with a custom title, would be to implement a custom dialog. You may want to look in to using jQuery UI Dialogs. There are many other implementations of custom Dialog controls. Such as SimpleModal Dialog.
The short answer is: no.
However, alert is a host method and browsers can chose to implement it however they like. But all browsers currently do not let script modify the standard alert dialogue. You can create your own alert dialogue though using a suitably styled and positioned element.
If you mean function renaming
<script type="text/javascript">
function hello(msg){
alert(msg);
}
</script>
Click Here

alert() prompt - Checkboxes

With alerts you can have text inputs. I was hoping you could put check boxes in. Is this possible?
http://www.w3schools.com/JS/js_popup.asp
No, you would need to build out a dialog box in order to achieve this.
You are able to achieve this with relative ease through jQuery and more specifically the jQuery UI plugin, allowing dialog boxes to come up without too much know-how
No. The only options are:
alert (display string);
confirm (display string and get yes/no|true/false back);
prompt (display string and get input string back)
You can create your own modal dialog using a variety of techniques. Under the hood, they all essentially do the same thing - display a separate web page in a popup window or iFrame and disable input access to the rest of the browser until the popup is closed. These are pretty easy to get wrong (hard to use + very annoying) but when done right they offer the developer a lot of power - since it's a complete web page you control, you can pass complex JavaScript objects between the dialog and the main browser window, instead of having to rely on the primitive interaction modes offered by the out-of-the-box dialogs.
Pretty shure it isn't possible. However, you can simulate a "alert box" with the contents you need. JQuery, for example, is a great javascript framework to achieve that.
no, but you can create a function that opens a alert box with html in it, like on facebook.
No, but you can create functions with alert boxes.
javascript:alert("Hello");
javascript:confirm("Hello");
javascript:prompt("Hello");
are the inly available ones.

Categories

Resources