How to change the title of a browser page which a servlet streamed a PDF to?

后端 未结 5 730
情歌与酒
情歌与酒 2020-12-09 04:55

My Java based webapp has a servlet which streams PDF content back to the browser based on request parameter.

e.g. user clicks on an A tag with an href of \"myApp/Fet

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-09 05:29

    I have hit this issue,and while my solution has quite a few restrictions I thought I would share it.

    Baiscally I will open the pdf in a new tab, and then change its title from the original page.

    $('#aa').click(function(){
        ref = window.open('resume.pdf','mywindow');     
        ref.onload = function(){
            ref.document.title="New Title";
        }
        return false;
        });
      });
    

    Note that the parent and child pages must be in the same domain.

    I have tested this in a few browsers, and here are the results:

    • Chrome 10 - Works like a treat
    • Safari 5 - Works, but by default opens in a new window not tab. User can change this to open all new windows in tabs.
    • IE 8 - Doesn't work, as expected :op
    • Firefox - Works like a treat

提交回复
热议问题