Daddy
Daddy

Reputation: 9035

UIWebView -stringByEvaluatingJavaScriptFromString: fill textbox in iFrame content?

I'm not a master of JavaScript and I'm having trouble, so I'm not sure if I'm doing it wrong or what I'm intending is not possible.

In my webpage, I have an iFramed chatbox. The chatbox has 3 text fields, one for username, one for email address, and one for the message. You can see it and inspect its content here: http://appsylvania.com/Chatroom.html

I want to automatically fill the username ("nme") and email ("eml") text fields with a javaScript call. I've inserted a function into the page itself like so:

function fillFields(name,email) {
    var nameText = document.getElementsByName("nme");
    nameText.value = name;
    var emailText = document.getElementsByName("eml");
    emailText.value = email;
}

So, shouldn't this work?

//in UIWebView didFinishLoad delegate method
[webView stringByEvaluatingJavaScriptFromString:@"fillFields('justin','[email protected]');"];

It doesn't seem to do anything. My guess is that it doesn't work because I'm either doing it wrong or javascript doesn't work on iFrame content.

Thanks for your help.

Upvotes: 1

Views: 1051

Answers (1)

Alex L
Alex L

Reputation: 8449

Did you try accessing via the iFrame?

var ifrm = document.getElementById('cboxmain5-697468');
var nameText = ifrm.getElementsByName("nme");

Upvotes: 1

Related Questions