-2

I am trying to align iframe to the center but for some reason it is showing from the left side whereas I want the iframe and it's elements to be on the center. I used the iframe inside a div but it's not working and showing from the left side. I want it to be dynamically aligned. Can anyone help?

<div id="modalReportView" class="modal fade" role="dialog">
    <div class="modal-dialog modal-report">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title modalhead" style="">Report Viewer</h4>
            </div>
            <div id="content" class="modal-body" style="padding: 15px 30px 30px 30px; background: #808080; overflow-x: hidden;">
                <iframe id="reportIframe" scrolling="no" style="width: 100%; height: 910px; border: none;">
                </iframe>
            </div>
            <div class="modal-footer">
                <div class="col-md-12">
                    <a href="#" class="btn btn-sm btn-danger btn-block" id="closeModalButton" data-dismiss="modal"><b><i class="glyphicon glyphicon-remove"></i> Cancel</b></a>
                </div>
            </div>
        </div>
    </div>
</div>
-----------JS code-------------------
function ViewReportDetails(_dbModel) {
$("#reportIframe").attr("src", "");

var ItemModuleFrom = jQuery.grep(moduleWiseReportClass, function (p, i) {
    return (p.Module == _dbModel.ModuleFrom);
});

_dbModel.ReportHelperClass = ItemModuleFrom[0].HelperClass;

var reportUrl = "/ReportsManagement/ReportView/ReportViewer?json=" + encodeURIComponent(JSON.stringify(_dbModel)); // for rdlc report
console.log(reportUrl);

////for rdlc report
$("#loading").show();
if ($("#reportIframe")[0].contentWindow.document.readyState === 'complete') {
    $("#reportIframe")
        .attr("src", reportUrl)
        .on('load', function () {
            $("#loading").hide();
            $("#modalReportView").modal('show');
        });
}
$("#closeModalButton").on('click', function (e) {
    $("#modalReportView").toggle();
});

}

6
  • "I am trying to align iframe to the center but for some reason it is showing from the left side - Unsure what you mean, the iframe has a width of 100% and thus is centered?
    – DarkBee
    Commented Jul 10 at 6:11
  • If you want to center the contents inside the iframe, then that needs to happen in the document loaded into the iframe. But we don't know if you have access to that to begin with.
    – CBroe
    Commented Jul 10 at 6:13
  • I can not add image right now as I don't have 10 reputation points at this otherwise I could have shown the issue. I am showing a RDLC report on a modal the problem is the report shows from left side but i want it to bow shown on the center. I can do it using margin-left but i wanted a dynamic way. That's all I'm asking. Is there any way to do so? Commented Jul 10 at 6:28
  • You can upload images to imgur and link them
    – mplungjan
    Commented Jul 10 at 6:33
  • You should modify the code to create an actual minimal reproducible example. There is no modal at this point either
    – DarkBee
    Commented Jul 10 at 6:41

0

Browse other questions tagged or ask your own question.