document.title in IE
Author
Discussion

BliarOut

Original Poster:

72,863 posts

262 months

Monday 22nd February 2010
quotequote all
Before I pull my hair out is there something I don't know about IE? (The answer to that is lots!)

I'm trying to set the page title of a user initiated popup which displays a gif image and it's not working, what am I missing?

I call this simple function

{{{
function popWindow() {
ElementWindow = window.open('images/print-bg.gif', 'popWin','width=680, height=550, resizable=0, menubar=0, toolbar=0');
document.title = "How To Print Background Colours";
}

}}}

From here

please click <a href=\"javascript:popWindow()\"><strong>here</a>




The window opens with the options I've set, but the page title remains as the location. It's on an intranet and will only ever be opened with IE so there are no issues with any other browsers.

I know I'm doing something stupid here banghead

anonymous-user

77 months

Monday 22nd February 2010
quotequote all
Are you changing the title of the main window? Shouldn't it be something along the lines of ElementWindow.document.title = 'sfsds'

Edited by anonymous-user on Monday 22 February 16:25

zac510

5,546 posts

229 months

Monday 22nd February 2010
quotequote all
It's not a html doc, it's a gif, are you sure you can set the window title?

If you loaded the gif inside an html file I'm sure doc.title would work.

miniman

29,352 posts

285 months

Monday 22nd February 2010
quotequote all
I think you need to put the document.title on the onload event of the popup window.

BliarOut

Original Poster:

72,863 posts

262 months

Monday 22nd February 2010
quotequote all
Bluequay said:
Are you changing the title of the main window? Shouldn't it be something along the lines of ElementWindow.document.Title = 'sfsds'
banghead Whoops, the parent window is changing. Told you I was doing something stupid paperbag

I too thought it should be:

ElementWindow.document.title = "How To Print Background Colours";

But I get a JS error confused

BliarOut

Original Poster:

72,863 posts

262 months

Monday 22nd February 2010
quotequote all
miniman said:
I think you need to put the document.title on the onload event of the popup window.
There is no document as such, I'm just launching a .gif in a new window.

anonymous-user

77 months

Monday 22nd February 2010
quotequote all
What JS error are you getting? Object is null?

BliarOut

Original Poster:

72,863 posts

262 months

Monday 22nd February 2010
quotequote all
I'm afraid I can't see it now as I've left for the day.

scratchchin Could it be as simple as 'ElementWindow' is a variable and JS doesn't allow variables beginning with a capital letter?

4hero

4,505 posts

234 months

Monday 22nd February 2010
quotequote all
NEVER USE CLICK HERE PLEASE!!!!!

What's wrong with including a descriptive link to the page, all in one paragraph?

As for your question, can't you just have a blank page containing the gif, and the <title> in the head of that page to change?

BliarOut

Original Poster:

72,863 posts

262 months

Monday 22nd February 2010
quotequote all
They get a description, I haven't included all the code. Decoration is set to none in the css as an aside wink

I don't want to include it in a page of it's own as that would mean maintaining it (and various others when I've done) when it's not really necessary. The link is to an animated gif that shows the end user visually how to enable background colour printing. If I can do this I can reuse that code instead of writing pages.

4hero

4,505 posts

234 months

Monday 22nd February 2010
quotequote all

BliarOut

Original Poster:

72,863 posts

262 months

Monday 22nd February 2010
quotequote all
4hero said:
It may well work although it isn't the look I really want. That said that's a superb link and I'm sure I'll put it to good use at some point. Thanks thumbup

4hero

4,505 posts

234 months

Monday 22nd February 2010
quotequote all
No worries. What type of look are you after? Lightbox is pretty flexible, there are many ways to do this. I'd be happy to help out wink

BliarOut

Original Poster:

72,863 posts

262 months

Tuesday 23rd February 2010
quotequote all
I just want an animated gif (It's a screen cap of running through changing a printer setting) in a window with a suitable title and the bare minimum of clutter.

When I change the code to what I think should run as it is below I get "unspecified error".

document.title = "How To Print Background Colours"; must be syntactically correct as it alters the parent window's title, but as soon as I precede it with elementWindow it spits an error. To my mind I'm not referencing the child window correctly but I can't see why.

{{{
function popWindow() {
elementWindow = window.open('images/print-bg.gif', 'popWin','width=680, height=550, resizable=0, menubar=0, toolbar=0');
elementWindow.document.title = "How To Print Background Colours";
}
}}}

JohnnyPanic

1,282 posts

232 months

Tuesday 23rd February 2010
quotequote all
The problem is 'document.title' refers to the HTML <title> element. As you're just loading a gif there is no 'document' or 'title' to reference.

So AFAIK you can't do it this way without using one of the myriad lightbox plugins, or placing the image in some containing HTML as suggested above.

Though on this note you could try something along the lines of:

function popWindow() {
elementWindow = window.open('blank.htm', 'popWin','width=680, height=550, resizable=0, menubar=0, toolbar=0');
elementWindow.document.write = "<html><head><title>How To Print Background Colours</title></head><body><img src="images/print-bg.gif" /></body></html>";
}

Where 'blank.htm' is a physical empty text document.

Disclaimer: I have not tested this!

BliarOut

Original Poster:

72,863 posts

262 months

Tuesday 23rd February 2010
quotequote all
Thanks, that was the problem. I was trying to alter a property of an object that didn't exist thumbup

JohnnyPanic

1,282 posts

232 months

Tuesday 23rd February 2010
quotequote all
BliarOut said:
Thanks, that was the problem. I was trying to alter a property of an object that didn't exist thumbup
No problem smile

Although I have just noticed some glaring syntax errors in my 'solution' but it's a bit late now.

BliarOut

Original Poster:

72,863 posts

262 months

Tuesday 23rd February 2010
quotequote all
Yup, it didn't work wink

Pointed me in the right direction though and I wouldn't have sorted it without that so thanks again.

zac510

5,546 posts

229 months

Tuesday 23rd February 2010
quotequote all
Hey I mentioned it in post 3! smile

BliarOut

Original Poster:

72,863 posts

262 months

Tuesday 23rd February 2010
quotequote all
Sorry Zac, thank you to you too tongue out