How do I use the HTML IFRAME element to embed content? - html

<!DOCTYPE html>
<html>
<head>
<title>My favorite app</title>
</head>
<body>
<iframe src="https://stackoverflow.com/questions/36047483/parsing-a-websites-
html-tags-in-iframe"></iframe>
<div class="title">My App</div>
<div class="app">
<div class="image"><img src="images/app.png" alt="this is a
screenshot" class="image"></div>
</div>
</body>
</html>
i tried to use iframe tag but it doesn't work and a blank section is appeared as that image.
the blank section that appears to me in the browsers.

That's because Stack Overflow disallows use inside a frame by setting X-Frame-Options to sameorigin...
So only is allowed as iframe inside Stack Overflow itself, not from your code.
Long version:
When your browser try to access that URL from Stack Overflow, Stack Overflow returns some headers, one of them is X-Frame-Options: sameorigin, that instructs your browser to disallow to display that URL inside an IFrame, so your browser refuse to do it.
Its a SO server config (you can't do anything about it).

The Stack Overflow page you reference in the src attribute is not displayed in the iframe element because the Stack Overflow site implements an iframe blocking policy. In order to do this, it uses the X-Frame-Options. (See also how to block website from loading in iframe?.)
You can check whether a site implements this policy by inspecting its HTTP headers. For example, in Firefox, press F12 to open the inspection tools, then go to Network, select one of the objects that were sent over HTTP and look at the headers (or filter the headers for e.g. "x-frame"). Below is what this looks like for the URL you tested:
Notice x-frame-options: SAMEORIGIN in the lower right part of the screenshot. With x-frame-options: SAMEORIGIN or x-frame-options: DENY set on the server side, you will not be able to load pages from that site inside an iframe or a frame.
For more background, see X-Frame-Options – How to Combat Clickjacking, which also explains other values that can be used in the x-frame-options header.
If you want to test with a webpage from a server that does not block loading in iframes, try for example https://wiki.archlinux.org/index.php/Tomcat.

Related

x-frame-options header set but can stilll embed in iframe?

The x-frame-options header is confirmed as set to SAMEORIGIN, but when creating a simplistic local HTML file e.g.
<html>
<head>
<title>Clickjack test page</title>
</head>
<body>
<p>Website is vulnerable to clickjacking!</p>
<iframe src="http://www.yoursite.com/sensitive-page" width="500" height="500">
</iframe>
</body>
</html>
and attempting to embed the target page i'm able to do so without issue.
What could be causing this?
Thanks
Some reasons I can think of:
Page is being loaded from the same origin, hence allowed.
"X-Frame-Options" or "SAMEORIGIN" is not spelled correctly and hence ignored.
Content-Security-Policy frame-ancestors directive is more permissive and X-Frame-Options is ignored when it is set. If this is the case it should be blocked in IE which doesn't understand Content-Security-Policy.
Your browser is more lenient with local files.

How to use a heroku app inside a html iframe?

I want to use this heroku app (spring boot) inside an iframe. https://sef-github-leaderboard.herokuapp.com/ but it doesn't work. it says refused to connect. Here's the code.
<!DOCTYPE html>
<html>
<body>
<iframe src="https://sef-github-leaderboard.herokuapp.com/" title="Iframe Example" style="height:500px;width:100%;"></iframe>
</body>
</html>
If you open up devtools, click the Network tab, refresh the page, and click the first item in the waterfall, you'll find that the Content Security Policy header X-Frame-Options is set to DENY on the URL you are seeking to embed. This instructs the browser to disallow loading the page within an iframe. To get around this, you would need to use a forward proxy to strip out the headers.

Unable to load an URL using iFrame because of Content Security Policy

<!DOCTYPE html>
<html>
<body>
<iframe src="URL">
<p>Your browser does not support iframes.</p>
</iframe>
</body>
</html>
I am using the above code to load the url inside iFrame and i am getting below error:
Refused to display 'URL' in a frame because an ancestor violates the following Content Security Policy directive: "frame-ancestors https://inteliapp-stage.grymatter.com URL1 URL2 URL3 URL4 URL5 URL6 URL7
http://18.233.166.250 https://18.233.166.250 cdn.jsdelivr.net".
For security reason, i am not able to mention the exact URLs. I want to know what should i add inside meta tag for content security Policy to resolve the problem? If we cant resolve the problem then how we can load the url inside html code.Please help me out. Thanks in advance.
The page you're trying to put in the frame has the policy that's being violated. There isn't any way to weaken CSP rules once sent; so unless you can modify the source of the framed page, there's not much you can do here.
You may be able to use an alternate method, such as doing an HTTP call in the background to fetch the content of that page, and manually insert that content into your page.

iframe not working. Everything looks correct [duplicate]

This question already has answers here:
Overcoming "Display forbidden by X-Frame-Options"
(27 answers)
Closed 6 years ago.
I tried creating an iframe. I have created an iframe before. But this one doesn't seem to work no matter what I do.
<!DOCTYPE html>
<html>
<head>
<title>DSCOVR</title>
</head>
<body>
DSCOVR:
<iframe src="http://epic.gsfc.nasa.gov/index.html" width="100%" height="1000px">loading...</iframe>
</body>
</html>
Link to jsfiddle with my code
It doesn't seem to work with any other websites either.
Open your browser's developer tools. Look at the console.
Mixed Content: The page at 'https://jsfiddle.net/mmzj1uge/' was loaded over HTTPS, but requested an insecure resource 'http://epic.gsfc.nasa.gov/index.html'. This request has been blocked; the content must be served over HTTPS.
You can't embed insecure content into an otherwise secure page.
If you look at the warnings (with Safari), there is one that says:
[blocked] The page at about:blank was not allowed to display insecure content from http://epic.gsfc.nasa.gov/index.html.
Like Quentin said:
My guess is that JSFiddle won't embed HTTP stuff because JSFiddle's website is HTTPS secured, and if it did, it would compromise security.
Hope this helped!

Access anchor tag attribute inside iframe

Parent domain: www.parent.com
Iframe domain: www.iframe.com
<html>
<head></head>
<body>
<iframe id="trick" src="www.iframe.com/test">
<html>
<head></head>
<body>
test
</body>
</html>
</body>
</html>
Question: how to access the value of href of anchor tag inside iframe using jquery?
Since they pages appear on different origins:
The page containing the frame needs to listen for a Message event.
The page inside the frame needs to send a message using postMessage.
This, obviously, requires changes on both sites. Explicit co-operation between the sites is required for obvious security reasons (if they aren't obvious, imagine your bank's website being loaded in an iframe by a random site you visited via Google).
Check this link: http://simple.procoding.net/2008/03/21/how-to-access-iframe-in-jquery/
$('#iframeID').contents().find('#someID').html();