首页 > 解决方案 > 如何设置在浏览器的新标签(_blank)中打开的pdf文件的标题

问题描述

这是我的尝试,它是否在 newtab 上打开,但它总是显示test pdf作为标题

function titlepath(path,name){
    alert(path);
    alert(name);
    document.title = name;
    window.open(path, '_blank');
}

标签: javascriptjquery

解决方案


这个解决方案对我有用。 问题:如何在新打开的选项卡中更改pdf的标题

     function titlepath(path,name){

        //In this path defined as your pdf url and name (your pdf name)

            var prntWin = window.open();
            prntWin.document.write("<html><head><title>"+name+"</title></head><body>"
                + '<embed width="100%" height="100%" name="plugin" src="'+ path+ '" '
                + 'type="application/pdf" internalinstanceid="21"></body></html>');
            prntWin.document.close();
        }

推荐阅读