-1

I want to popup iframe src(domain) when script load. I code simple code but it does not working.

<html>
<title>Iframe load</title>
<iframe src="https://evil.com/" id="site" width="800px" heigth="700px"></iframe>
<script>
  var siteD = document.getElementById("site");
    alert(siteD);
</script>
</html>

When page load its only showing me [object HTMLIFrameElement]. But i want to show in popup evil.com from src. I hope you understand my question.

1
  • You should use console.log Commented Jul 1, 2020 at 7:50

2 Answers 2

1

The cause: alert() wants to show a string, which is why it applies toString() to its parameter, and that does not render any of the properties of the object.

You need to use alert(siteD.src); instead:

var siteD = document.getElementById("site");
alert(siteD.src);
<iframe src="https://evil.com/" id="site" width="800px" heigth="700px"></iframe>

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

Comments

0

There's a simple answer to your question, siteD has a property src which you need to be alerting instead of siteD on its own.

Here is an example with src as property: https://codepen.io/dwaynehulsman/pen/rNxYYWQ

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.