cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
adgkred
Resolver III
Resolver III

IFrame in form

Hey all,

 

So I'm working on a model-driven app and I'm trying to use an IFrame in a form to automatically perform a web search of the name of an entity. My event library contains the following code:

 

function WebSearch(fc) {
    var Url = "https://bing.com/search?q=";
    var formContext = fc.getFormContext();
    var Name = formContext.getAttribute("new_name").getValue();
    var IFrame = formContext.ui.controls.get("IFRAME_Web_Search");    
    var Url = Url + Name;
    IFrame.setSrc(Url);
}

 

 When I play the app, I don't get any errors from the script, however it only display the generic bing.com webpage, not the specific search I'd like to have.

 

I'm not very familiar with JS and tried a bunch of different things without any success, so if you have any idea that could help I'd greatly appreciate it.

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
v-xiaochen-msft
Community Support
Community Support

Hi @adgkred ,

 

 

Unfortunately, I was unable to reproduce the issue.

vxiaochenmsft_0-1664762612354.png

vxiaochenmsft_1-1664762648063.png

 

vxiaochenmsft_2-1664762693549.png

vxiaochenmsft_3-1664762712027.png

 

Result:

vxiaochenmsft_4-1664762765782.png

vxiaochenmsft_5-1664762790546.png

vxiaochenmsft_6-1664762804229.png

vxiaochenmsft_7-1664762825647.png

 

Maybe a foolish question... Did you publish the form?

vxiaochenmsft_8-1664763063570.png

 

Besides, please try to clear the browser cache or change a browser...

 

Best Regards,

Wearsky

View solution in original post

5 REPLIES 5
v-xiaochen-msft
Community Support
Community Support

Hi @adgkred ,

 

Unfortunately, I can't reproduce the problem.

Is it possible that the field value is empty?

If you try this code, does the popup have a value?

function WebSearch(fc) {
    var Url = "https://bing.com/search?q=";
    var formContext = fc.getFormContext();
    var Name = formContext.getAttribute("new_name").getValue();
    alert(Name);
    var IFrame = formContext.ui.controls.get("IFRAME_Web_Search");    
    var Url = Url + Name;
    IFrame.setSrc(Url);
}

// add alert in line 5

 

Besides, did you use that code in the onload event?

I researched the document and found the code is not recommended for use in onload event because it may be overwritten by the default value of iframe control.

vxiaochenmsft_0-1664527648919.png

https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/use-iframe-and-web-resource...

 

So what's the default value of your iframe control?

vxiaochenmsft_1-1664527815609.png

 

Best Regards,

Wearsky

adgkred
Resolver III
Resolver III

Hey @v-xiaochen-msft thanks for your answer.

I add the alert(name) but didn't get any popup, although the value definitely isn't empty. I strongly suspect that my code actually doesn't run in the IFrame because I tried different thing and setting the url to a static value but still nothing happened. 

I feel like I'm just missing a tiny piece but just don't know what it could be.

 

Here are more screenshots of my components:

https://www.bing.com/ is my default URL.

adgkred_2-1664547154638.png

My library element in JS:

adgkred_0-1664547041761.png

My event Handler, with OnReadyStateComplete being the only option I have:

adgkred_1-1664547089399.png

 

v-xiaochen-msft
Community Support
Community Support

Hi @adgkred ,

 

 

Unfortunately, I was unable to reproduce the issue.

vxiaochenmsft_0-1664762612354.png

vxiaochenmsft_1-1664762648063.png

 

vxiaochenmsft_2-1664762693549.png

vxiaochenmsft_3-1664762712027.png

 

Result:

vxiaochenmsft_4-1664762765782.png

vxiaochenmsft_5-1664762790546.png

vxiaochenmsft_6-1664762804229.png

vxiaochenmsft_7-1664762825647.png

 

Maybe a foolish question... Did you publish the form?

vxiaochenmsft_8-1664763063570.png

 

Besides, please try to clear the browser cache or change a browser...

 

Best Regards,

Wearsky

adgkred
Resolver III
Resolver III

Hey @v-xiaochen-msft, thanks again for the reply. 

I tried doing everything from scratch again but still didn't have any success. I ended up seeing my events weren't in the tab list by default, so I added them, and finally got the result I was hoping for... So I guess it was coming from here all this time 😅

adgkred_0-1664786723550.png

 

Thanks a lot for taking the time to help me!

 

v-xiaochen-msft
Community Support
Community Support

Hi @adgkred ,

 

Did you mean that you forgot to add the tab event handler before and it worked after adding it ?  😃

 

Best Regards,

Wearsky

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Power Apps Ideas

Check out the New Ideas Site

We are excited to announce a new way to share your ideas for Power Apps!

Top Solution Authors
Top Kudoed Authors
Users online (4,552)