最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Set Browser Title for PDF Page - Stack Overflow

programmeradmin0浏览0评论

I load a pdf that the user clicks on via a URL call. See the following javascript:

$("ul.card[data-entry-id]").css("cursor","pointer").on("click",
    function(event)
    {
        document.location = "/archives/entry/" + $(this).attr("data-entry-id");
    }
);

I want to change the browser title of the pdf that es up, so that it is not just the url. Adding document.title("New Title") to the function block does not work because it is not synchronized with the server returning the file that's being displayed in the browser. How can I overe this?

Perhaps I could open a new page (rather than changing the document location) that wraps the URL call in html so that I can set the title - something like this:

<html>
    <head>
        <title>New Title</title>
    </head>
    <body>
        <iframe src="/archives/entry/98"></iframe>
    </body>
</html>

And that way, I could set the title. How can I write this html to a new page from within the javascript function block I have that responds to a click? Thanks in advance.

I load a pdf that the user clicks on via a URL call. See the following javascript:

$("ul.card[data-entry-id]").css("cursor","pointer").on("click",
    function(event)
    {
        document.location = "/archives/entry/" + $(this).attr("data-entry-id");
    }
);

I want to change the browser title of the pdf that es up, so that it is not just the url. Adding document.title("New Title") to the function block does not work because it is not synchronized with the server returning the file that's being displayed in the browser. How can I overe this?

Perhaps I could open a new page (rather than changing the document location) that wraps the URL call in html so that I can set the title - something like this:

<html>
    <head>
        <title>New Title</title>
    </head>
    <body>
        <iframe src="/archives/entry/98"></iframe>
    </body>
</html>

And that way, I could set the title. How can I write this html to a new page from within the javascript function block I have that responds to a click? Thanks in advance.

Share Improve this question asked Dec 14, 2013 at 22:36 sehcheesesehcheese 1751 gold badge2 silver badges8 bronze badges 1
  • Uhm, changing the documents location does open a new page, so anything you do in the current page after the call to document.location has no effect, as a new page is loaded. – adeneo Commented Dec 14, 2013 at 22:42
Add a ment  | 

3 Answers 3

Reset to default 2

If you set a title in the PDF document you can make it display as your browser title.

Follow these instructions:

http://www.w3/TR/WCAG20-TECHS/PDF18.html

Instead of changing location you can load data by ajax.

$("ul.card[data-entry-id]").css("cursor","pointer").on("click",
    function(event)
    {
        var title = $(this).text();
        var url = "/archives/entry/" + $(this).attr("data-entry-id");
        document.body.innerHTML = "<p>Loading...</p>"; // Or a loading image

        $.ajax(url).done(function(data){
            $(document.body).html(data);
            document.title = title;
        })
    }
);

A jQuery approach, relatively easy to modify for plain JavaScript:

$('body').html('<iframe src="/archives/entry/98">');
document.title = "New Title";
发布评论

评论列表(0)

  1. 暂无评论