Tapeshwar Kumar
Tapeshwar Kumar

Reputation: 21

How to use iframe in CodeIgniter?

I am using below code to display iframe

<iframe src="www.w3schools.com" width="100%">
            <p>Your browser does not support iframes.</p>
</iframe>

But it is not working and showing result like.

https://i.sstatic.net/7ywKS.png

and when I check console and found

https://i.sstatic.net/WY8zL.png

Upvotes: 1

Views: 3915

Answers (3)

Danyal Sandeelo
Danyal Sandeelo

Reputation: 12391

<iframe src="https://www.w3schools.com" width="100%">
            <p>Your browser does not support iframes.</p>
</iframe>

That's what you see in console when you inspect the page.

Refused to display 'https://www.w3schools.com/' in a frame because it set 'X-Frame-Options' to 'sameorigin'.

You cannot use all the sites to be shown within the iframe on your site. Here is a good read on this issue.

How to set 'X-Frame-Options' on iframe?

Upvotes: 1

Valdeir Psr
Valdeir Psr

Reputation: 702

The error is because you are accessing w3schools.com, this causes the browser to 'think' which is a file, not a complete url.

The correct one is https://www.example.com or http://www.example.com

Before adding a site to an iframe, you should check the headers that the site brings in the response. At the w3schools.com site, the server reports the x-frame-options: SAMEORIGIN header.

This header informs whether or not the site can be added to an iframe, frame, or object. When the header value is SAMEORIGIN, only the w3schools.com site can add its pages to the iframe.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options

Upvotes: 0

Matiur Rahman Mozumdar
Matiur Rahman Mozumdar

Reputation: 451

Use this code:

<iframe src="<?php echo site_url('www.w3schools.com');?>"> </iframe>

Upvotes: 0

Related Questions