This question was probably asked few time by now... but I didn't find any solution in the last 2 days so I'm asking it in here.
I need to inject some text into a textbox that has an ID and I already know it. the scenario is like that:
The user insert a text into the textbox inside my toolbar.
The user clicks on a button in my toolar.
The function in the button should redirect the user to a new page in the background, inject a text into a specified textbox and click a button in that webpage.
Return a link that is generated on the webpage.
I know how to open a new webpage. now all is left is the rest.
I can't seem to inject the text into the specified textbox.
Also to note, I can't use greasemonkey on this project and that's why I will have to write everything I'll need to write.
If you can direct me to the starting point for this problem it would be nice.
The textbox is XUL textbox or html textarea?
It look like your scenario is simulate submit a form in background, why not just directly create a XMLHttpRequest to do this, no need to interactive with UI.
Update:
If it is a XUL textbox, you can use value property
var textbox = window.document.getElementById(textboxId);
if (textbox) {
textbox.value = 'your text';
}
Related
I'm currently using Tampermonkey to inject JavaScript into specific web pages.
For my job, I have to constantly fill in numerous text boxes on the same web page with the same exact information. So instead of manually copying and pasting everything to each separate text box, I'd like to be able to synchronize my input on one text box with another. So as an example, theoretically, I could type "dog" into the first box, and the word "dog" would appear in the second box automatically. Is this possible in Tampermonkey via JavaScript?
I'm assuming <input type="text"> and/or an element ID or name could be used to link the interaction of two elements on a specific page?
I'm not exactly sure where to get started here, so any and all advice would be deeply appreciated.
To synchronize all text boxes on the page, you could do something like this:
document.addEventListener("input",function(e) {
if (e.target.matches("input[type=text]")) {
document.querySelectorAll("input[type=text]").forEach(function(a) {
a.value = e.target.value;
});
}
});
I have an input text field in which the user can enter the name of a website. Is it possible for it to be hyperlinked so that once the field is saved, if the user clicks on it, it redirects to the website?
I use Django for the backend and Javascript and html for the front end.
An input field's value is stored as plain text, therefore you cannot include HTML (i.e. a link) and expect the HTML to be parsed and functioning.
You could simulate this behavior with JavaScript, however I would recommend against it. (You would add a click listener, your function would pull the value of the field, see if it is a valid URL, and then open up the location.)
I'm not going to write the code for this because it would be a terrible user experience. The standard behavior for an input field is that you click on it to edit the text. This is an assumption your users have, and they would therefore (a) not think to click on it because they don't expect it to be a link, and (b) click in it if they wanted to edit the text, only to be redirected and unable to edit the text.
Alternatively, you could add a small button next to the input, i.e. 'Open' or 'Test' or an external link icon.
Simply, if you are printing the URL for the user on their profile page, sure you can just print it as follows:
<a href='$url'>$url</a>
That's PHP but of course you can do this in any language. I'm not sure if this answers your question since you ask if it can be printed "inside" the field which isn't possible/doesn't make sense.
HOWEVER, think about security. Remember the user can enter any malicious URL into this field, so you need to be aware of who you are potentially linking this to on your website/application.
Useful resources:
URL HTML field:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/url
Validate URL format with Django (does not check if malicious or not though):
How can I check if a URL exists with Django’s validators?
I'm using an iframe to get the content of a registration form on a web page, and, as I have to show this registration form inside an HTML app for Android, I'd like to analyse the html inside the iframe to search for input textfields and to use my custom text field as "dummy" or "proxy" for the considered element:
Let me explain better:
As the web page wouldn't give the user the same easy approach as an app, instead of clicking on a textfield and having the problem that the virtual keyboard overlaps the other fields making it difficult to go further.
I want to create a div that covers the iframe and has a text field inside with the same functionality as the one clicked: by this way after entering the text into the dummy field and clicking an ok button aside, the clicked field would be updated and all the other things hidden (virtual keyboard, etc.).
It would be simple if the goal was just to copy a text from a field to another, but the real problem is that the clicked field could have some events like onkeypress or onchange (e.g. to autocomplete) and so on, and I should get the same behaviour on the dummy field.
In an imaginary world I'd do:
document.getElementById("dummy") = document.getElementById("original")
And then destroying and recreating the dummy whenever required.
Do you know if is there something possible to do?
You can't read a div from inside of an iframe after the iframe has loaded. The reason for this is to prevent hackers from making programs that can grab your credit card numbers from web-based forms through iframes and then use the apps to record them.
UPDATE
You would have to retrieve the entire form in the background, then render it again using webkit, then when the person clicks submit, you would have to submit the exact same form data to the host from your device.
Its possible, but I don't see a good reason why you would ever need to use that.
I have spent a couple of days looking for something to accomplish my needs, and I have been unable to find it.
I have a basic HTML input box in a parent window that has text in it (from a MySQL query). I need to be able to generate a popup window that shows a textarea which contains this same text. I would then need to be able to edit the text in the textarea, press a button, and have it close the window, and send the text back to the parent window's input box.
I am indifferent to the use of jquery, as I am already loading it for other elements on the page. I just want whatever works. Thank you for your help.
Is there a method to fill the textfield from a Facebook comment plugin using javascript?
I know how to fill the text into textbox of website using active control by javascript, but it doesn't seem to work on the Facebook comment plugin.
eg. if I click the hello button I want to fill the active textbox text with "hello".
You will need to make sure that you execute your action after the textfield appears in your UIWebView. However, I will highly recommnend making a delegate method instead, detecting the facebook button click, and use the Facebook SDK instead.
Much more freedom instead of having to "hijack" the html and manipulate it after load.