I have a UI with a print button, i want to create an iframe on click of the print button, is it possible using javascript?
In this article. Apart from accessing an element by adding its control to the Controls Repository, there is also the possibility to access an element within a web page's iframe via Javascript.
The Button is a widget for iFrame granting you an opportunity to build various buttons for different purposes on your website. There are tons of actions that can be taken after a user clicks the button.
document.getElementById('print-button').onclick = function() {
var iframe = document.createElement('iframe');
iframe.src = 'http://example.com';
document.body.appendChild(iframe);
};
Of course, if you're intending to attach more events of the same type, use addEventListener()
.
If jQuery is at your disposal...
$("#print-button").click(function() {
$("<iframe />", { src: "http://example.com" }).appendTo("body");
});
Sure...#printbutton is the ID of your print button.
<a href="#" id="printbutton">Print</a>
<div id="iframe_parent"></div>
<script src="PATH-to-JQUERY"></script>
<script>
$('#printbutton').click(function(){
var iframe = document.createElement('iframe');
iframe.setAttribute('src', 'path/to/iframe/page/');
document.getElementById('iframe_parent').appendChild(iframe);
});
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With