'I am trying to open a new url page and get the title of new page

I am trying to open a new url page and get the title of new page.

issue: it is openning new page but the title is for previous page, (not new page).

 // open pdf in new window page 
        var url = 'http://myserver/mywebsite/Files/folder12/folder3/myfile.pdf';
        location.href = url;

        //get the title of new page 
        var title = $('title').text();

        //display new page title
        alert(title);


Solution 1:[1]

I think the problem you have is the new webpage is not a real page. It's a pdf, you can't get a page title from a pdf file.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tkun