1

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.

1
  • 1
    Per this question stackoverflow.com/questions/1088544/… it appears that you can't access iFrame content from another domain, that is classified as cross-site scripting and is not allowed. Commented Mar 22, 2012 at 18:23

1 Answer 1

1

Did you try accessing via the iFrame?

var ifrm = document.getElementById('cboxmain5-697468');
var nameText = ifrm.getElementsByName("nme");
Sign up to request clarification or add additional context in comments.

3 Comments

No I didn't because honestly I'm not familiar with javascript other than some online tutorials =). Will try again
ok, didn't work, but i changed a couple things. The chatbox has 2 iFrames, the second iFrame is what holds the textboxes, and it is called "cboxform5-697468". So I changed my script to reflect that. I wish there was an easier way to debug this.
For debugging Chrome has developer tools and javascript console in View>Developer. For firefox you can download Firebug. Then you can easily browse elements and variable console.log(variables).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.