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

javascript - Setting the page title of Chrome window.open - Stack Overflow

programmeradmin1浏览0评论

I have some JavaScript that is being used to open a new window and display a PDF file. This is working fine apart from the title of the new window being open. I am using the window.open function and I have set the title of the page using the document.write function (see code below). The code works fine for FF and IE but for some reason Google Chrome just displays 'Untitled - Google Chrome'

<body>
    <a href="javascript:openNewWindow();">Click Here</a>

    <script type="text/javascript">
        function openNewWindow()
        {
            var pdfWindow = window.open('', "window",
                'resizable=1,scrollbars=0,width=800,height=600');

            pdfWindow.document.write('<html><head><title>Window Title</title></head>');

            pdfWindow.document
                    .write('<body><iframe src="" id="ifrm" name="ifrm" width="100%" height="100%"></iframe>');

            pdfWindow.document.write('</body></html>');

            pdfWindow.document.close();
        }
    </script>
</body>

Note: I have also tried adding - pdfWindow.document.title="Title"; - to the JavaScript, with no luck.

Is there anything specific that is required for Chrome or am I just missing something??

I have some JavaScript that is being used to open a new window and display a PDF file. This is working fine apart from the title of the new window being open. I am using the window.open function and I have set the title of the page using the document.write function (see code below). The code works fine for FF and IE but for some reason Google Chrome just displays 'Untitled - Google Chrome'

<body>
    <a href="javascript:openNewWindow();">Click Here</a>

    <script type="text/javascript">
        function openNewWindow()
        {
            var pdfWindow = window.open('', "window",
                'resizable=1,scrollbars=0,width=800,height=600');

            pdfWindow.document.write('<html><head><title>Window Title</title></head>');

            pdfWindow.document
                    .write('<body><iframe src="" id="ifrm" name="ifrm" width="100%" height="100%"></iframe>');

            pdfWindow.document.write('</body></html>');

            pdfWindow.document.close();
        }
    </script>
</body>

Note: I have also tried adding - pdfWindow.document.title="Title"; - to the JavaScript, with no luck.

Is there anything specific that is required for Chrome or am I just missing something??

Share Improve this question asked Feb 14, 2011 at 15:40 WillWill 3202 gold badges4 silver badges12 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 8

Works for me when I set the 1st parameter of open() to 'about:blank'

You need to specify the url in the first parameter, like "about:blank":

window.open('about:blank', "window", 'resizable=1,scrollbars=0,width=800,height=600');

It will work on Chrome in incognito mode. So the issue is caused by an extension, probablly adblock. Disabling the extensions will solve this issue.

The pop up dialogue/window was blocked by chrome browser by default. If you change settings, that will do.

发布评论

评论列表(0)

  1. 暂无评论