Code inside iframe is loaded on windows load. However, contents of body loads after button click. And div with id="headers" is hidden but shown on another link click.
What I want is to access and alert Some Id on click search button.
How can I achieve this using Javascript or jQuery?
Here is my Html code:
<html>
<head>
<title>TODO</title>
</head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<body>
<div id="btn">
<button id="btn-search">Search</button>
</div>
<div class="iframebox">
<iframe id="messageiframe" srcdoc='
#document
<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body class="full-height">
<div id="preview">
<ul id="list">
<li class="mail"><a href="https://mail.gmail.com">Gmail</a></li>
<li class="search"><a href="https://www.google.com">Google</a></li>
<li class="mail"><a href="https://mail.outlook.com">Outlook</a></li>
<li class="search"><a href="https://www.bing.com">Bing</a></li>
</ul>
</div>
<div id="all" style= "display: none;">
<div id="headers">
<font class="bold">Path</font>
"Some path"
<br>
<font class="bold">doc Id</font>
"Some Id"
<br>
<font class="bold">Recieved</font>
"Me"
</div>
</div>
</body>
</html>'>
</iframe>
</div>
</body>
</html>
Here is my Javascript code which is incomplete:
$('#btn-search').on('click', function() {
// slight delay
setTimeout(function(){
var links = [];
var iframe = document.getElementById('messageiframe');
iframe.contentWindow.onload = function(){
var innerDoc = iframe.contentWindow.document;
};
},100);
});
Any help is appreciated. Thanks in advance.