How to set title in window popup when URL points to a PDF file?

不羁岁月 提交于 2020-01-16 20:18:34

问题


In javascript I create a URL which points to a PDF and open a new window. The window title contains the URL which I would like to hide from the user.

I tried the following suggestion Set title in the window popup but this doesn't seem to work for PDFs.

Is there a way to solve this problem?


回答1:


You cannot hide the URL that way, but you can create a popup window with custom content and embed the PDF file inside, instead of directly linking to the PDF file.

Like:

<html>
<head>
<title>This is your title</title>
</head>
<body>
<iframe src="your_pdf_file_link"></iframe>
</body>
</html>

But if the client don't have a PDF plugin, they will always receive a "Save As" dialog.




回答2:


Use instead window.open onclick of hyperlink. In window.open pass the url of your pdf. this way you would be control the window by setting its tittle, it size etc etc




回答3:


Maybe the new window could be an HTML page and you could display the PDF in an iframe? Pass all the information you need to the new window in the query string.




回答4:


Thanks for the iframe tip. This is what worked for me:

<script type="text/javascript">
var birtwin = null;
var birturl = null;
function birt(report, params) {
    var url = "http://myserver/webapps/birt/run?__report=Report/" + report + "&__lc=<%= user.getLocale() %>&__format=pdf&__runtime=<%= LoginServlet.isTest() ? "test" : "prod"%>&";
    var chk = document.getElementById('chkPageBreak');
    if(chk && chk.checked) url += "PageBreak=true&";
    if(params) {
        params = params.replace('%MMSFAIRID%', '<%= user.getFair().getFairId() %>');
        params = params.replace('%LANGUAGE%', '<%= user.getLocale().getLanguage() %>');
    }
    url += params;
    birturl = url;
    birtwin = window.open('','MMSBIRT', 'menubar=0,location=0,toolbar=0,resizable=1,status=1,scrollbars=1');
    checkbirt(); // start checking
}

function checkbirt() {     
    if(birtwin.document) { 
        birtwin.document.write('<html><head><title>Bericht / Report</title></head><body height="100%" width="100%"><iframe src="' + birturl + '" height="100%" width="100%"></iframe></body></html>');
    } else { 
        // if not loaded yet
        setTimeout(checkbirt, 10); // check in another 10ms
    }
} 



来源:https://stackoverflow.com/questions/11135487/how-to-set-title-in-window-popup-when-url-points-to-a-pdf-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!