-3

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);
404
  • 1
  • 1
  • After you redirect to a new page, the current script stops running. – Barmar Apr 18 '22 at 15:25
  • i didnt think of that. that make sense why its not geeting the new title. - do you know how can i get the title of 'location.href = url;' – 404 Apr 18 '22 at 15:27
  • are you trying to open pdf in a new window and display title in current window? – Jatin Parmar Apr 18 '22 at 15:29
  • Use `window.open()` to open it in a new window instead of redirecting the current window. – Barmar Apr 18 '22 at 15:30
  • yes but doesnt has to be display, a alert box is ok. I have bunch of pdf urls where the links can change over time. I want to get the title to see if its contains "404". thsi way I can tell that link is broken, rather than manually linking on each links – 404 Apr 18 '22 at 15:31
  • You can open the url in an iframe to get the title – Tanay Apr 18 '22 at 15:35
  • 2
    Going to have an issue because the new page is not a webpage, it would be a PDF. There is better ways to see if it is a 404. https://stackoverflow.com/questions/3646914/how-do-i-check-if-file-exists-in-jquery-or-pure-javascript – epascarello Apr 18 '22 at 15:46

1 Answers1

-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.

Tkun
  • 69
  • 2