0

I'm trying to figure out in Angular 2 how to do the following

Enter a url into the address bar and load an iframe based on that URL

For instance,

localhost:3000/http://test.com should load a full screen iFrame of test.com

Could anybody provide any reference to this?

1 Answer 1

2

There's no any in-box solution in angular package. But I see you could make it with next steps:

  • create FrameComponent component that will show iFrame the way you need
  • configure route to match FrameComponent
  • Navigate by url and extract path from activatedRoute
  • add url to iframeSource
  • profit

But you'll meet some issues - cross origin navigation, not safe url, etc. One of them could be fixed with DomSanitizer and SafeResourceUrl from @angular/platform-browser.

A made some proof to show what I mean:

https://plnkr.co/edit/9sgwAy?p=preview

Sign up to request clarification or add additional context in comments.

2 Comments

The help is much appreciated. Any idea why it won't work with http, and instead only with https/
Because of fundamental principal of web security. If you have an HTTPS site, you can only embed iframes from HTTPS sources. There are couple of technics to resolve this limitation. But this issue is out of scope. Feel free to google https to http proxy, https mixed content, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.