web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Accessing iframe values in the form

(0) ShareShare
ReportReport
Posted on by 2,665

Hi,

I have an iframe on the form which contains a label and I am trying to access that label value on form save through javascript onsave event.

Like this:

Xrm.Page.ui.controls.get('IFRAME_FileUpload').getObject().contentWindow.document.getElementById('StatusLabel').value;

But I am getting this error when I debug:

'Error: Permission denied to access property "document"

What does this error mean? I have the checkbox 'Unchecked' for 'cross scripting' iframe properties.

Thanks for any help.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    razdynamics Profile Picture
    17,308 User Group Leader on at

    HI roxanna

    How are you authenticating user access to the Iframes Website?

  • Suggested answer
    Aiden Kaskela Profile Picture
    19,696 on at

    Hi Roxanna,

    Per msdn.microsoft.com/.../jj602964(v=crm.7).aspx , the Xrm.Page.ui.controls.get('IFRAME_FileUpload').getObject() method returns an iframe element, so you'll have the properties and methods available here: msdn.microsoft.com/.../ms535258(v=VS.85).aspx

    contentWindow is documented, but instead of contentWindow.document try: contentDocument

    Hope this helps! I'd appreciate if you'd mark this as Answering your question.

    Thanks,

     Aiden

    EDIT: document isn't a valid property of the window property. Changing it to contentDocument should fix the issue. Per: https://msdn.microsoft.com/en-us/library/ms535873(v=vs.85).aspx#properties

  • crmprogrammer2013 Profile Picture
    2,665 on at

    I tried your suggestion:

    Xrm.Page.ui.controls.get('IFRAME_FileUpload').getObject().contentDocument.getElementById('StatusLabel').value;

    I am seeing this error now:

    There was an error with this field's customized event.

    Field: crmForm

    Event: onsave

    Error: undefined

    Thanks.

  • crmprogrammer2013 Profile Picture
    2,665 on at

    Hi Raz CRM,

    Anonymous Authentication and Asp.net authentication.

    Thanks.

  • Suggested answer
    Aiden Kaskela Profile Picture
    19,696 on at

    Can you put some logging (or even alerts) around that statement and break it up to see what's actually coming back null, something like this:

    var frame = Xrm.Page.ui.controls.get('IFRAME_FileUpload');

    var frameObj = frame.getObject();

    var theDoc = frameObj.contentDocument;

    var label = theDoc.getElementById('StatusLabel');

    var theValue = label.value;

    This will help you narrow down which object is causing the error.

    Thanks,

     Aiden

  • meenoo Profile Picture
    7,316 on at

    .

  • Suggested answer
    ScottDurow Profile Picture
    21 on at

    This sounds like a cross domain scripting issue. If the Iframe is from a different domain to CRM then you'll not be able to access it due to the same domain access policy. See madskristensen.net/.../iframe-cross-domain-javascript-calls

    Hope this answers your question

  • meenoo Profile Picture
    7,316 on at

    Interesting..

  • crmprogrammer2013 Profile Picture
    2,665 on at

    Thanks, Scott.

    Yes, the iframe is in different domain to CRM. How else can I access values from iframe?

    What are my other options. I definitely need some connection between the form and iframe.. Please suggest.

  • Verified answer
    crmprogrammer2013 Profile Picture
    2,665 on at

    Okay.. I figured a way myself and instead of messing up with these cross browser scripting.. I've decided to capture the file details and create a record all through server side coding and it was smooth.

    So as the file gets uploaded on 'upload' button click event, I am creating a record with all the uploaded file data. And its working for my requirement.

    Thanks guys for suggestions.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans