Saturday, February 19, 2011

Accessing Controls on page loaded in IFrame in MS CRM 4.0 using Javascript

Hello All

I have a custom aspx page loaded in a IFrame in one of the modules in MS CRM 4.0. This page basically has 6 textboxes (txtValue1, txtValue2 and so on..) with values in it. I want to access these values through javascript code either on the load event or save event. Does anybody know how to do it ? I tried couple of codes that i got from net but nothing seems to work. Any help on this would appreciated.

From stackoverflow
  • Try the following snippet...

    var textBox1Value = document.frames.IFRAME_NAME.document.all.txtValue1.value;
    

    where IFRAME_NAME is the name of the IFRAME you define in the form customizations and txtValue1 is the id of the textbox on the IFRAME.

  • Thanks a ton buddy :). It works just fine, thanks again :)

  • I am trying to get a value of a control in my iframe page, but throwing error "Access is denied."

    someone please help me....

  • I am trying to get a value of a control in my iframe page, but throwing error "Access is denied."

    the code is

    var textBox1Value = document.frames.IFRAME_NAME.document.all.txtValue1.value;

    someone please help me....

    Polshgiant : Go to the form's customization page, double-click the iframe, and make sure that the "Restrict cross-frame scripting" is unchecked. Save and Close. Publish the entity.
  • One little gotcha that's worth noting is that accessing the iframe via the document's frames collection won't let you read or write the src or url properties that I find myself dynamically changing every now and again. To access and change the properties, you'll need to access the iframe via getElementById.

    var yourIframe = document.getElementById('IFRAME_NAME');
    

    Note that if you access the iframe as above and you want to call a function that is available to the iframe's scripts, you have to call it via the contentWindow property:

    yourIframe.contentWindow.someFuncOnIframePage();
    

0 comments:

Post a Comment