I have one URL which generates PDF file. For generating PDF, i am using iframe to load that url and generate PDF file in same page for users.
When user click on button, it will show loader
in screen. and it should be hide when iframe load complete(when PDF download popup). I used below code, but its not working, loader
remain show after download popup open (if i change url with any other like google.com then it will work).
Here is my code snippet.
$("#test").click(function(){
iframe = document.getElementById("download-container1");
if (iframe === null)
{
$("#ajax_loading").show();
var url="http://test.coachfxlive.com/ajax/ajax-action.php?type=s&vid=0&playlist_id=11&perpage=1&action=get_profile";
iframe = document.createElement('iframe');
iframe.id = "download-container1";
document.body.appendChild(iframe);
$('#download-container1').load(function () {
$("#ajax_loading").hide();
});
iframe.src=url;
}
});
.ajax_loading {
background-color: rgba(0, 0, 0, 0.7);
display: none;
height: 100%;
left: 0;
position: fixed;
top: 0;
width: 100%;
z-index: 99999;
}
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<div class="ajax_loading" id="ajax_loading"><span>Please Wait... Loading</span></div>
<button id="test">click</button>
</body>
</html>
When iframe
complete load, need to hide div ajax_loading
.
Am i doing anything wrong here? is there any other solution?
Thanks in advance.