Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening a new tab in the browser and sending info to it?

Status
Not open for further replies.

matterhorn2001

Programmer
Feb 12, 2009
4
US
Hello all,
I am a bit of a newbie to JS, so I am not sure if this is even possible...so here goes.

I am looking to have a JS page with a few input boxes and a submit button. Once the submit button is pressed, the script will open a new tab in the browser and send the contents of the text boxes to input boxes on the newly opened web page. For example, a username and password would be entered on the JS page and sent to the newly opened page to log the user in to the other system.

Any ideas on if this is a possibility? Please let me know if more info is needed.

Thanks so much!
-Matt
 
Are the pages on the same domain, or are you trying to write code to log into a 3rd-party website?

If the latter, then chances are it won't accept login requests from a domain other than its own (unless you know otherwise).

Dan


Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Hi Dan,
Thanks for the reply. I am basically attempting to have the user enter their login/password on my end and then push those credentials over to AdWords to have the user then access their account.

My ultimate goal is to have the user populate the text boxes with their credentials on my page, and then log into AdWords and run a report which is emailed back to them.

I have accomplished this using the Chickenfoot Firefox add-on, however I would like to achieve this same functionality using JS (so the user will not need to rely on a FF add-on).

Again, any help would be greatly appreciated.

Thanks!
-Matt
 
You could probably do it provided you know enough about the other page.

Like the names or ID's of the form and the inputs in the other page you wish to populate.

Code:
function send_login_to_other_win(){
var mywin=window.open('http:\\[URL unfurl="true"]www.server.com\page.html','mywindow');[/URL]
alert("Logging into AdWords...");
mywin.document.formname.fieldname.value="value from this page";
mywin.document.formname.fieldnametwo.value="password from this page";
mywin.document.myform.submit();

}

The only caveat is you absolutely need the alert so that the window has enough time to to load everything, otherwise you'll get errors of undefined elements.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Hi Phil,
Thanks for the info. I think this will work, however after doing some testing, I just want to make sure I am implementing it as you suggest. Here is a snippet of what I have:


mywin.document.gaia_loginform.Email.value = document.feedback.name.value;

mywin.document.gaia_loginform.Passwd.value=
document.feedback.pass.value;

mywin.document.gaia_loginform.submit();

In this case, document.feedback is my form name...and gaia_loginform is the name of the form on the AdWords login page. "Email" and "Passwd" are the names of the fields.

Is this the correct interpretation? Again, thanks for the help.

-Matt
 
Like I said - you need to know whether they accept form submissions from another domain (or even another protocol if this is a local file).

If they do not, then this script will not work (although I guess one way of finding out is to run it).

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
That's pretty much correct, assuming mywin, is the variable returned by the window.open command.

Technically all this is doing is submitting their form. So they should technically accept that. Its not sending values into directly into their processing script, but rather using their actual form form their page to submit the values.


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top