4

I have the following jquery code and I have inserted it in an html page where I call it inside an iframe in a SharePoint page. I am using this line of code to get the id from the control in the parent page

var id = $('#prodId', window.parent.document).val()

but it is not working.

Any idea how to access objects in the parent page from within iframe?

  function formatItem(item) {
      return item.Name + ': $' + item.Price;
  }

  function find() {
      //var id = $('#prodId').val();
      var id = $('#prodId', window.parent.document).val()
      $.getJSON(uri + '/' + id)
          .done(function(data) {
              alert(formatItem(data));
              $('#product').text(formatItem(data));
          })
          .fail(function(jqXHR, textStatus, err) {
              alert(err);
              $('#product').text('Error: ' + err);
          });
  }

2 Answers 2

1

Where is the page for the iFrame hosted? If you're in an app or in another domain, it won't work, check out

3
  • it is hosted in a different domain/web application.
    – Imir Hoxha
    Sep 26, 2014 at 12:38
  • so there is really no way of accessing it
    – Imir Hoxha
    Sep 26, 2014 at 12:43
  • related: what are script app parts and how does Script Editor Webpart do this? are they embedded inline? Possible to develop a web part that works the same way? See my post.
    – Hell.Bent
    Jan 16, 2015 at 16:50
1

If it is in a different domain there are options (CORS) msdn blog

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.