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/
Related
On my website I want to link to a web-app, automatically inserting some text into a textarea.
Is it possible to link to the website doing something like this?
www.website.com/#document.getElementById('textarea').value ='inserted text';
This bookmarklet is working code, I just want to use a link to the website and somehow get it to run the bookmarklet automatically.
javascript:{document.getElementById('textarea').value = 'inserted text'; void(0)}
Any suggestions/ideas?
On my website I want to link to a web-app, automatically inserting some text into a textarea.
You cannot, unless that web-app provides a means for you to do so (for instance, passing information on a query string or otherwise as part of the URL). You can't create a link that runs JavaScript on the page after loading it, not without the page's cooperation.
On the off-chance that the target web-app is also under your control: You could, of course, add a feature to the web-app to do it. If so, be sure you just accept a value and don't allow executing arbitrary JavaScript code passed to you on the URL, that would be a Very Bad Idea unless the target page never shows anything user-specific (and probably even if it doesn't).
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.
I would like to take a given text from a document and copy it to a pop-up window (window.open) that contains a form generated by a server-side back end (rails in this case) this form is loaded from a different domain that the present document, containing the text to be copied. This text would be displayed in the form (reviewed by the user) and then be submitted to the server, through a POST form action.
I initially wanted to use document.write() but this will not be possible since the pop-up page will be loaded from a different domain.
Query strings in this case will not help due to the limits on chars. Any other options?
Most modern day browsers support window.postMessage where you can pass information to the new window.
If you are working with older browsers, your best bet is to post a form to that domain's page with the content and that server will read the posted data and fill out the form.
You best bet will probably be to have a script in the popup window call for the text from the other screen. Rather than try and pass it to the popup window.
Use an ajax call to the main page and get the text for the text field and update the text field when you get it.
I think you should use zero-clipboard-rails. See zero-clipboard-rails on github.
If you can edit the page that is loaded in the new window then here s something you can do using JavaScript. Before opening the new window, set the copied text to a variable in the parent window.
var copiedText = 'text to be copied'; //e.g. $('#some-textarea').val()
Then load the new page. Inside the new page add a call to the 'opener' window's variable using
opener.copiedText
and use it to populate the form element.
I'm fairly new to Javascript. I'm trying to write a pretty basic program that will display the results of a form in a popup window after being submitted by the user.
I've got a form with all the relevant IDs. My problem is accessing this form from within the popup window. I've been playing around with window.opener.formid1, window.parent.formid2, document.forms[0] changing values where necessary, trying anything my countless searches have returned, but all I seem to get are "undefined" errors. I tried defining my variables in several different places but after a lot of testing I'm getting nowhere.
I'm aware you can use, for example
var popup = window.open("popup.html")
popup.document.write('')
which works fine but I don't want to overwrite the contents that are already in there and unless I'm mistaken, there isn't a way to append or edit a file.
If someone can offer a solution or any feedback, it'd be much appreciated. Thanks.
Have you tried: popup.document.getElementById('formID').appendChild. I beleive that should work.
If I understand it correctly, you are trying to submit your form and want to display the result in a new pop up.
If you want to submit your form and want to get the response use the AJAX which is again javascript. You can get AJAX examples from google for your assistance.
As you have already mentioned, writing on popup or sending value to the popup (may be through query string) would work after you receive the result from AJAX request.
From the popup, the following should work:
var form = window.opener.document.getElementById('formid1');
// Get data from form here.
I hope someone can help me. I'm trying to access the text box inside a webpage so I can do some scripting, e.g. placing text in fields, checking a box and clicking submit, to automate my employees' workflow. It's confusing as heck because I cannot find the name/id/whatever that will allow me to manipulate the form. I can see the name of the field I'm trying to get at using Firebug ("history[comment]") and the id, if that helps ("history_comment") but no matter what I do, the form will not be manipulated. Based on the other scripting I've done, this Applescript:
do JavaScript "document.forms[1].history_comment.value='Testing';" in document 1
should do the job, telling the browser to put "Testing" in the appropriate field. I've substituted other names I think might be what it wants, and tried referencing any other forms (forms[2], forms[3]), all for naught. I'm actually confused a bit more because there are no statements in the HTML, so it could be I'm screwing up there.
I've posted an HTML dump of the form at http://images.jlist.com/testform.html (with dummy information of course) in case any kind soul can take a gander and give me some direction. My goal is to be able to put information into the Comment field. Is there a script I can run that will tell me the complete name (as far as the browser is concerned) of every element in the form?
if you can use jquery, then you can do it quite easily using the following command
$("history_comment").val("HELLO");
The JavaScript should be:
document.getElementById("history_comment").value='Testing';
document.forms is non-standard and, as is the case in your example code, fails if the element is not inside a form. This is fairly common in AJAX applications and another good reason to avoid document.forms.
What #Kikuchyo wrote, though it's actually strictly incorrect not to enclose form elements like textarea in a form tag. You'll also need that form tag if (as you suggest) you want to submit the form programmatically. Since you're already accessing that text box, you can get the form from that in your javascript function:
var thetext=document.getElementById('history_comment');
thetext.value='whatever you want to put in there';
thetext.form.submit(); // all form elements have a 'form' property
You can get at the checkbox state as document.getElementById('history_notify').checked; it's a Boolean value, so set it to true or false, and use it in conditionals directly.
Of course, if (as, looking at the form, you likely want to) you want an AJAX submit, you'll need to check out the documentation for whatever wrapper library you're using.
since your element is a text area, it should be done like this:
document.getElementById('history_comment').innerHTML = 'HELLO';
using innerHTML instead of value