Q:

SharePoint 2013 App Part and Modal Dialogs

I've created a SHP 2013 Sharepoint-Hosted App on visual studio.
On my App.js that's created by default, i have the following lines to show a Modal Dialog
var options = { url: 'http://www.google.com', width: 400, height: 300 };
SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);

It works as intended, the little dialog is shown correctly.
After that, i've created a new Client Web Part (App Part) on visual studio, and on the aspx file for my app part i have the same JS lines
<script type="text/javascript">
    var options = { url: 'http://www.google.com', width: 400, height: 300 };
    SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
</script>

But this time it returns an error saying the reference to the property 'execute' is null or undefined.
Is it possible to invoke a modal window from within a App Part? What changes from invoking it from the Default page of my app?
Thanks in advance.

A:

you should include Microsoft SP JavaScript API in order to use SP.SOD.
<script type="text/javascript" src="../Scripts/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.js"></script>

And also check in you Default.aspx page if there is code that you have not included in your App Part page.
edit : If you want to access objets and function of the page containing the iFrame, you can type parent. before your call. e.g. parent.SP.SOD.execute('...'); I hope this will work.

