1

Using Javascript in a webBrowser Control in a form, How do I switch to a iFrame

<iframe id="ContentFrame" class="contentIFrame" onload="checkComplementaryPage()" onmouseover="hoverMenu('dividers')"  name="ContentFrame" src="HomeContainer.aspx" scrolling="auto" frameborder="0"></iframe><div id="footer" class="footer">

and then locate and click on an element inside that iFrame?

<div class="innerItem50L">
   <input type="submit" name="btnPunch" value="punch" id="btnPunch" style="CURSOR:hand;" />
</div>

I am new to programming and am starting with c#. I know even less about Javascript...

Sean Connelly
  • 135
  • 3
  • 13

1 Answers1

0

Using the following thread as an example:

Make an event happen in child iframe to the parent window in JavaScript?

You could do the following:

 $('#ContentFrame').contents().find('#btnPunch').click();

Note: The iframe's source has to be from the same domain, and contents must be loaded so you should put it after window load.

Community
  • 1
  • 1
Aston
  • 3,654
  • 1
  • 21
  • 18
  • The frame is in the same domain, but is in a different sub-domain. Is that alright? – Sean Connelly Sep 01 '15 at 20:15
  • Yes, just set the domain to the parent domain in the subdomains: http://javascript.info/tutorial/same-origin-security-policy#the-document-domain-exception – Aston Sep 01 '15 at 20:40
  • Is this in JavaScript or JQuery? I am unable to implement this. The "$" is showing an unexpected character and both of the # sections are showing as "Too many characters in character literal." – Sean Connelly Sep 01 '15 at 20:58
  • I think your comment about the domain and subdomains is based on me having access to the html. I do not have this access. Will this solution still work once I figure out how to implement JQuery into my code? – Sean Connelly Sep 02 '15 at 16:45
  • No. Javascript can only access web pages from the same origin. https://en.wikipedia.org/wiki/Same-origin_policy – Aston Sep 02 '15 at 18:53