Get the URL of the document that is shown in an iframe:
var x = document.getElementById("myFrame").src;
Click the button to display the value of the src attribute in the iframe.
<!DOCTYPE html> <html> <body> <iframe id="myFrame" src="https://www.java2s.com"></iframe> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {//from w w w . j av a2 s .c o m var x = document.getElementById("myFrame").src; document.getElementById("demo").innerHTML = x; } </script> </body> </html>