Is it possible to modify the title of the message box the confirm() function opens in JavaScript?
I could create a modal popup box, but I would like to do this as minimalistic as possible.
I would like to do something like this:
confirm("This is the content of the message box", "Modified title");
The default title in Internet Explorer is "Windows Internet Explorer" and in Firefox it's "[JavaScript-program]." Not very informative. Though I can understand from a browser security stand point that you shouldn't be able to do this.
This is not possible, as you say, from a security stand point. The only way you could simulate it, is by creating a modeless dialog window.
There are many third-party javascript-plugins that you could use to fake this effect so you do not have to write all that code.
YES YOU CAN do it!! It's a little tricky way ; ) (it almost works on ios)
var iframe = document.createElement("IFRAME");
iframe.setAttribute("src", 'data:text/plain,');
document.documentElement.appendChild(iframe);
if(window.frames[0].window.confirm("Are you sure?")){
// what to do if answer "YES"
}else{
// what to do if answer "NO"
}
Enjoy it!
Not possible. You can however use a third party javascript library that emulates a popup window, and it will probably look better as well and be less intrusive.
You can always use a hidden div and use javascript to "popup" the div and have buttons that are like yes and or no. Pretty easy stuff to do.
You can't unfortunately. The only way is to simulate this with a window.open call.
Don't use the confirm() dialog then... easy to use a custom dialog from prototype/scriptaculous, YUI, jQuery ... there's plenty out there.
I know this is not possible for alert(), so I guess it is not possible for confirm either. Reason is security: it is not allowed for you to change it so you wouldn't present yourself as some system process or something.
Yes, this is impossible to modify the title of it. If you still want to have your own title, you can try to use other pop-up windows instead.
Related
I'm sure you can help me with this issue:
I recently run into some issues with opening a new tab / pop-up on a php/javascript site.
My current solution is as followed:
<script type="text/javascript">
function Popup(url) {
window.open(url);
}
</script>
<div class="link_box">
<a class="link_box_link" href="javascript:Popup('http://www.<website>.com')"><website-name></a>
</div>
However some of my coworkers using IE6-8 can't seem to open the link. Now I hope you can help me finding the best possible and cross-browser compatible solution for opening a new tab or window. Any help or tip would be greatly appreciated!
Ok, after looking at the comments produced (mine included), I decided that I should sum it up in an answer.
The cross-browser compatible solution is simply this: (with no Javascript)
LINK TO GOOGLE
Read about it here.
There are a few reasons why this may not work:
browser settings;
pop-up blockers
About these, there isn't much you can do. Browser settings aren't editable by your script; AFAIK, there isn't a general way to circumvent pop-up blockers (and thank god for that!).
Although, there are a few workarounds that do work under specific conditions. Although, as it may be such a frustrating task to account and inquire about all those conditions with a script, my suggestion of using a modal window with an iframe still stands.
NOTE: Actually, using this should not bring that many trouble with pop-up blockers (though still possible). Note that most times pop-up blockers are triggered exactly by detecting client-side scripting to open new windows - being the method you tried possibly one of the first to trigger it.
You have to manipulate the target like Joum saved in the comment section. Or you simple are using the posible to return false;.
<a class='popup' href='www.websitename.com'>website</a>
$('a.popup').live('click', function(){
newwindow=window.open($(this).attr('href'),'','height=200,width=150');
if (window.focus) {newwindow.focus()}
return false;
});
I was looking into making Firefox addons, and I need some help.
Is it possible to edit an HTML page that is open in the browser with javascript?
For example:
User types in "google.com"
Addon is activated
Javascript changes contents of "google.com" to maybe say "Hello!" at the bottom.
Of course this isn't specifically what I want to do, but a push in the right direction on how to accomplish such a task would be great.
~Carpetfizz
From within a Firefox addon this is obviously possible as many extensions do this.
If you, however, simply want to modify the DOM and nothing else than I would recommend taking a look at greasemonkey. Loads of example scripts around to do this: http://userscripts.org/
And the added benefit, if written correctly they also work in Chrome and other browsers.
Yes, it is. You must find a tutorial about javascript DOM manipulation
I use :
Window.showModalDialog(...)
to open a dialog window,
I want show some HTML code in this window, but I don't have a file. (Can't use URL to visit)
like show "hello world!" in this dialog window.
Can I do it?
Interesting question!
I'm not an expert in modal dialogs, but I don't think you can, because it's in the nature of a modal dialog to block any further code from being executed until the window is closed again.
I thought about using a data: URI that you could use as the first argument to showModalDialog instead of a normal URL:
window.showModalDialog("data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D" ....);
but according to the MSDN page on data: URIs, that will not be supported in Internet Explorer. (see the "Remarks" section on the linked page)
It might work in Firefox, though: More on data URIs at Mozilla Developer Central
Update: It works in Firefox: JSFiddle but, as expected, not in IE. You only get a blank window there.
Good question and answer. (+1)
I just thought I'd add, that if you do need to enter HTML into a modal dialog, you may want to look into using a Javascript library to accomplish it. I've used Dojo's "dijit.Dialog" several times with HTML, including images, form controls etc... You can style it however you like, and it works well cross-browser.
You can check out a few example of dijit.Dialog's use over at DojoCampus.
Cheers.
Please tell me, how to apply CSS on javascript Alert.
Thanks
You cannot. alert() simply shows a native message box, so it'll look however the OS makes it look.
In general, you shouldn't be using alert boxes because they are annoying and they block the entire browser.* You could always create a fake alert box with JavaScript that achieves the same effect. You could then style it however you want with normal CSS. If you use jQuery, there's SimpleModal (demos).
* Modern browsers tend to only block the window that spawned the alert, but they're still annoying and you still shouldn't use them. :)
It is not possible, or else people will use it to phish.
you might want to check jConfirm (jQuery plugin)
http://abeautifulsite.net/2008/12/jquery-alert-dialogs/
No you can't do that. I would suggest you either let it be, or use a modal window. You can also try using modal/dialog plugins e.g. http://docs.jquery.com/UI/Dialog
You can use the sweet alert library of js
official website
github
You can also customize the alerts with simple CSS.
I am in need of a popupwindow with the option of a radio button. I have tested with Impromtu. Is any easy made Popupwindow plugin available?
My plugin should work in Internet Explorer, Mozilla and Google Chrome. What would some sample code be?
jqModal is great and easy-to-use for building Modal Popups and the like.
If you want a tutorial on how to build one yourself without jQuery, check out this tutorial.
Check out Thickbox! You can use a div or so on your page as content (see inline content demo).
Here's a list of lightbox like plugins depending on your need:
http://www.fortysomething.ca/mt/etc/archives/006978.php
If you're not absolutely bent on using jQuery, there is another library available that uses the Prototype library that is rather handy. The popup windows are very easy to implement, and the modal dialog boxes are even easier.
On a side note, I have used thickbox before and was rather impressed, but the URL parsing structure that it uses were kind of limiting me for what I needed to do (I was using a ComponentArt object that didn't use anchors).
Anyway, definitely check out this tool. It's probably more than you need, but who knows maybe you'll get inspired to find other uses for it. It's a pretty fun tool:
http://prototype-window.xilinus.com/documentation.html
FaceBox is another option to check out.