Skip to content Skip to sidebar Skip to footer

How To Show Window Title Using Window.open()?

I want to open a new window using: window.open('.pdf','my window','resizable,scrollbars'); The new window opens, but I do not get the title of the window as 'my wind

Solution 1:

If domain is same then you can change the title of new window

<scripttype="text/javascript">var w = window.open('http://localhost:4885/UMS2/Default.aspx');
    w.document.title = 'testing';
 </script>

Solution 2:

Here is my solution, please check this out:

var myWindow = window.open('<myfile>.pdf','my window','resizable,scrollbars');
myWindow.document.write('<title>My PDF File Title</title>');

Hope I could help.

Solution 3:

This is what I did:

<scripttype="text/javascript">
    function OpenWindow() {
            var pdf = '<%= "PDFs/13.7/" + ddlLinkValidation.SelectedValue.ToString() + ".pdf" %>';
            var win = window.open('','UATRpt', 'menubar=0,location=0,toolbar=0,resizable=1,status=1,scrollbars=1');

            if(win.document) { 
                win.document.write('<html><head><title>Your Report Title</title></head><bodyheight="100%"width="100%"><iframesrc="' + pdf + '"height="100%"width="100%"></iframe></body></html>');
            } 
            return true;
    } 
    </script>

in HTML body <U><A style="cursor: pointer;" onclick="OpenWindow()">Open in New Window</a></U>

Solution 4:

If the new window has a file (PDF for example) as an url, it’s possible that the page has no "head" tag.

You have to add one before to modify / add the title.

jQuery :

var w = window.open('/path/to/your/file.pdf');// or any url
$(w.document).find('html').append('<head><title>your title</title></head>');

Native js :

var w = window.open('/path/to/your/file.pdf');// or any url
w.document.getElementsByTagName('html')[0]
   .appendChild(document.createElement('head'))
   .appendChild(document.createElement('title'))
   .appendChild(document.createTextNode('your title'));

Now if the page is long to load, you may add a onload watch, then also a timeout. In my case, I had to code like that :

var w = window.open('/path/to/your/file.pdf');// or any url
w.onload = function(){
    setTimeout(function(){
       $(w.document).find('html').append('<head><title>your title</title></head>');
    }, 500);
} // quite ugly hu !? but it works for me.

Solution 5:

The JavaScript "title" argument is a variable to be used inside of JavaScript. The actual title written in the top of the window normally comes from the HTML <title> tag, but you don't have that since you're showing a PDF.

Post a Comment for "How To Show Window Title Using Window.open()?"