cancel
Showing results for 
Search instead for 
Did you mean: 

Iframe in sapui5 xml views

Former Member
0 Kudos

Hi all,

i am using iframe inside my XML views , i need to change the src attributes of the iframe dynamically,

in that i am using google doc viewer

while i am trying to set src of iframe its giving 'SAMEORIGIN' issue,

but if we fixed the same url then it is working fine.

below code is for iframe in xml view,

<html:iframe target='_top' src="https://docs.google.com/viewer?url=http%3A%2F%2Ftsddev.cname.net%2Fecomm%2FAGR0000000005.pdf&embedde..." id ="attachmentframe" height="100%" width="100%">

</html:iframe>

if user clicks on a button i am trying to change the src of iframe as follows

document.getElementById("__xmlview4--attachmentframe").src = pathFormed

if we are placing the same url in pathFormed varaibale it will giving error.

can you any one help .

Thanks

Kotesh.

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi all,

Here is my code for iFrame,

in XML View

<html:iframe target='_top' src="" id ="attachmentframe" height="100%" width="100%">

</html:iframe>

in Controller i tried in two ways                        

var pdfUrl = "https://docs.google.com/viewer?url=http%3A%2F%2Fvtxdev.Pivog.net%2Fecomm%2F3M%2F0000006673%2Fdocumnt...";
   // $('#'+this.getView().byId('attachmentframe').sId).attr("src",pdfUrl);
   document.getElementById("__xmlview4--attachmentframe").src = pdfUrl;

              

after this if we are checking the src of the iframe it is getting empty and as well as getting SAME-ORIGIN" error

Former Member
0 Kudos

Hi Karthik,

if i am trying above example i am getting error like below

"in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'."

if we are directly given the url of the iframe it is working fine otherwise it's getting same origin error.

Thanks

Kotesh.

karthikarjun
Active Contributor
0 Kudos

Hi Kotesh,

I hope this will be helpful to you.

Thanks,

Karthik A

saivellanki
Active Contributor
0 Kudos

Hi Kotesh,

Try like this:


var oFrame = sap.ui.getCore().byId("__xmlview4--attachmentframe"); //Get Hold of iframe

var oAttributes = oFrame._xContent.attributes; //iframe Attributes

var oValues = {"target": oAttributes[0].value, "src":oAttributes[1].value, "id":oAttributes[2].value, "height":oAttributes[3].value, "width": oAttributes[4].value}; //Attribute Values

alert(JSON.stringify(oValues)); //Alert the Attributes

Check the sample here: Plunker

Once you got hold of the attributes, I hope you know how to change them.

Regards,

Sai Vellanki.