By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,767 Members | 1,034 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,767 IT Pros & Developers. It's quick & easy.

Problem with reload

P: n/a
Hey everyone,

I'm writing a script that opens the current page into a new window
with a different style sheet for printing, don't ask me why it needs
to open into a new window, it's a request from powers that be! Anyway
when I reload the page in IE it's fine but in FF it seems to render
the html without a style sheet!!?? I think it may be to do a caching
problem in FF with new windows but I'm not sure. Heres the code I've
written:

var w, d, copy;
//
function printPage()
{
document.getElementById('pageTitle').innerHTML = document.title;
w = window.open('', '' ,'');
d = w.document;
copy = "<html>\n<head>\n<title>"+document.title+"</title>\n";
copy += "<link id='globalStyleSheet' type='text/css' rel='stylesheet'
href='css/globalPrint.css' />\n";
copy += "<link id='docStyleSheet' type='text/css' rel='stylesheet'
href='"+document.getElementById('docStyleSheet').h ref+"' />";
copy += "<script language='javascript' type='text/javascript'
src='scripts/js/utils.js'></script>\n";
copy += "\n</head>";
copy += "\n<body>";
copy += document.body.innerHTML;
copy += "\n</body>\n</html>";
d.write(copy);
d.close();

}

function init()
{
document.getElementById('printLink').onclick = function(){
printPage();
return false;
}
}

I've been racking my brain for a few days now and have finally come to
a brick for a work around..

Any help or your thoughts would be much appreciated :)

Cheers

Feb 20 '07 #1
Share this Question
Share on Google+
15 Replies

P: n/a
On Feb 20, 10:23 am, "DoomedLung" <doomedl...@googlemail.comwrote:
Hey everyone,

I'm writing a script that opens the current page into a new window
with a different style sheet for printing, don't ask me why it needs
to open into a new window, it's a request from powers that be! Anyway
when I reload the page in IE it's fine but in FF it seems to render
the html without a style sheet!!?? I think it may be to do a caching
problem in FF with new windows but I'm not sure. ...
<snip>

More likely it is an issue with the relative URL for the style sheet
being relative to a page URL that is not the URL you are expecting.
Try adding a BASE element to assert the starting point for relative
URLs on the page (or use absolute URLs).

Richard.

Feb 20 '07 #2

P: n/a
On Feb 20, 10:40 am, "Richard Cornford" <Rich...@litotes.demon.co.uk>
wrote:
On Feb 20, 10:23 am, "DoomedLung" <doomedl...@googlemail.comwrote:Hey everyone,
I'm writing a script that opens the current page into a new window
with a different style sheet for printing, don't ask me why it needs
to open into a new window, it's a request from powers that be! Anyway
when I reload the page in IE it's fine but in FF it seems to render
the html without a style sheet!!?? I think it may be to do a caching
problem in FF with new windows but I'm not sure. ...

<snip>

More likely it is an issue with the relative URL for the style sheet
being relative to a page URL that is not the URL you are expecting.
Try adding a BASE element to assert the starting point for relative
URLs on the page (or use absolute URLs).

Richard.
Hey Richard, thanks for your speedy reply! Unfortunately I've tried
going with the absolute URL route (because I don't know what BASE
elements are? I really should!) and to no avail. FF still renders the
pages without a style sheet after reload!!?? :(

Feb 20 '07 #3

P: n/a
On Feb 20, 10:40 am, "Richard Cornford" <Rich...@litotes.demon.co.uk>
wrote:
On Feb 20, 10:23 am, "DoomedLung" <doomedl...@googlemail.comwrote:Hey everyone,
I'm writing a script that opens the current page into a new window
with a different style sheet for printing, don't ask me why it needs
to open into a new window, it's a request from powers that be! Anyway
when I reload the page in IE it's fine but in FF it seems to render
the html without a style sheet!!?? I think it may be to do a caching
problem in FF with new windows but I'm not sure. ...

<snip>

More likely it is an issue with the relative URL for the style sheet
being relative to a page URL that is not the URL you are expecting.
Try adding a BASE element to assert the starting point for relative
URLs on the page (or use absolute URLs).

Richard.
Hey Richard. I added a BASE element in the document but still no joy!?
FF still renders the page with out the style sheets applied!!??

Feb 22 '07 #4

P: n/a
ASM
DoomedLung a écrit :
Hey everyone,

I'm writing a script that opens the current page into a new window
with a different style sheet for printing, don't ask me why it needs
to open into a new window, it's a request from powers that be! Anyway
when I reload the page in IE it's fine but in FF it seems to render
the html without a style sheet!!?? I think it may be to do a caching
problem in FF with new windows but I'm not sure. Heres the code I've
written:
Not seen big errors
except perhaps </foo where </ is not escaped

That bellow works for me :

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="fr">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<title>Untitled special</title>
<link id='docStyleSheet' type='text/css' rel='stylesheet'
href='css/globalPrint.css' />
<script type="text/javascript">

var w, d, copy;
//
function printPage()
{
document.getElementById('pageTitle').innerHTML = document.title;
copy = "<html>\n<head>\n<title>"+document.title+"<\/title>\n";
copy += "<link id='globalStyleSheet' type='text/css' "+
"rel='stylesheet' href='css/globalPrint.css' />\n";
copy += "<link id='docStyleSheet' type='text/css' "+
"rel='stylesheet' "+
"href='"+document.getElementById('docStyleSheet'). href+"'/>";
copy += "<script language='javascript' type='text/javascript' "+
"src='scripts/js/utils.js'><\/script>\n";
copy += "\n<\/head>";
copy += "\n<body>";
copy += document.body.innerHTML;
copy += "\n<\/body>\n<\/html>";
w = window.open('', '' ,'');
d = w.document;
d.open();
d.write(copy);
d.close();

}

function init()
{
document.getElementById('pageTitle').innerHTML = 'vi';
document.getElementById('printLink').onclick = function(){
printPage();
return false;
}
}
onload = init;
</script>
</head>
<body>
<h1>titre</h1>
<p>The title : <span id="pageTitle"></span></p>
<p><a href="#" id="printLink">to see</a></p>
</body>
</html>
And file css/globalPrint.css :

h1 { color: red }
Take care your files exist and are stored in right place.

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Feb 23 '07 #5

P: n/a
ASM
DoomedLung a écrit :
On Feb 20, 10:40 am, "Richard Cornford" <Rich...@litotes.demon.co.uk>
wrote:
>On Feb 20, 10:23 am, "DoomedLung" <doomedl...@googlemail.comwrote:Hey everyone,
>>I'm writing a script that opens the current page into a new window
with a different style sheet for printing, don't ask me why it needs
to open into a new window, it's a request from powers that be! Anyway
when I reload the page in IE it's fine but in FF it seems to render
the html without a style sheet!!?? I think it may be to do a caching
problem in FF with new windows but I'm not sure. ...
<snip>

More likely it is an issue with the relative URL for the style sheet
being relative to a page URL that is not the URL you are expecting.
Try adding a BASE element to assert the starting point for relative
URLs on the page (or use absolute URLs).
With code given : that doesn't open a new window
we are far from styles sheet or not ...
>Richard.

Hey Richard, thanks for your speedy reply! Unfortunately I've tried
going with the absolute URL route (because I don't know what BASE
elements are? I really should!)

tag base (in 1st position in head)

<base href="http://myServer/mySite/myFolder/">

<base target="_parent">
<base target="myFrame">

<base href="http://myServer/mySite/myFolder/" target="_blank">
and to no avail. FF still renders the
pages without a style sheet after reload!!?? :(
Escaping closing tags in document.write(...)
could work better

My test with FF works fine (for me)

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Feb 23 '07 #6

P: n/a
ASM
DoomedLung a écrit :
>
Hey Richard. I added a BASE element in the document but still no joy!?
FF still renders the page with out the style sheets applied!!??
as waited ... (why a base tag could fix the problem ?)

But it is not normal,
there is no reason style sheets could be not loaded
(if they are with an other browser)
except if something in JS is only understood by IE

Put your complete code on line and give its url

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Feb 23 '07 #7

P: n/a
I've tried using the base tag elements and when I refresh after the
new window has beem created FF still seems to render the pages without
the style sheets attached.

Feb 23 '07 #8

P: n/a
ASM
DoomedLung a écrit :
I've tried using the base tag elements and when I refresh after the
new window has beem created FF still seems to render the pages without
the style sheets attached.
To what and at who do you answer ?

Once more without more information no help possible.
(My test is OK, FF use the Style Sheet window.writed)

You certainly do an error somewhere not seen in your post(s).

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Feb 23 '07 #9

P: n/a
On Feb 23, 12:21 am, ASM <stephanemoriaux.NoAd...@wanadoo.fr.invalid>
wrote:
<snip>
as waited ... (why a base tag could fix the problem ?)
<snip>

What is the URL of a browser window opened with - window.open('', '',
'') - ? Often it will be "about:blank" (or some browser dependent
variation on the theme). If you then remotely - document.write - to
the page loaded as - about:blank - the browser may change the URL to
that of the page doing the writing, or it may not (and some certainly
have not in the past). And if "about:blank" is the URL of the page how
will relative URLs be resolved?

Richard.

Feb 23 '07 #10

P: n/a
On Feb 23, 1:04 pm, ASM <stephanemoriaux.NoAd...@wanadoo.fr.invalid>
wrote:
DoomedLung a écrit :
I've tried using the base tag elements and when I refresh after the
new window has beem created FF still seems to render the pages without
the style sheets attached.

To what and at who do you answer ?

Once more without more information no help possible.
(My test is OK, FF use the Style Sheet window.writed)

You certainly do an error somewhere not seen in your post(s).

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
OK heres a working example: http://www.doomeddeveloper.com/newWindowTest.html

Click the link to open a new window then once the new window has been
created refresh the page and you'll see the styles change...

Feb 23 '07 #11

P: n/a
On Feb 23, 9:51 am, "DoomedLung" <doomedl...@googlemail.comwrote:
I've tried using the base tag elements and when I refresh after the
new window has beem created FF still seems to render the pages without
the style sheets attached.
All the speculation that is possible based upon the code fragment you
posted have been proposed. At this state your best option is to
demonstrate the phenomenon you describe in action, which can only be
done with a URL as factors such as HTTP headers may well come into the
picture (and cannot be known form posted code).

Richard.

Feb 23 '07 #12

P: n/a
On Feb 23, 1:22 pm, "Richard Cornford" <Rich...@litotes.demon.co.uk>
wrote:
On Feb 23, 9:51 am, "DoomedLung" <doomedl...@googlemail.comwrote:
I've tried using the base tag elements and when I refresh after the
new window has beem created FF still seems to render the pages without
the style sheets attached.

All the speculation that is possible based upon the code fragment you
posted have been proposed. At this state your best option is to
demonstrate the phenomenon you describe in action, which can only be
done with a URL as factors such as HTTP headers may well come into the
picture (and cannot be known form posted code).

Richard.
OK heres a working example: http://www.doomeddeveloper.com/newWindowTest.html

Click the link to open a new window then once the new window has been
created refresh the page and you'll see the styles change...

Feb 23 '07 #13

P: n/a
On Feb 23, 2:35 pm, DoomedLung wrote:
Richard Cornford wrote:
<snip>
OK heres a working example:http://www.doomeddeveloper.com/newWindowTest.html

Click the link to open a new window then once the new window
has been created refresh the page and you'll see the styles
change...
Firefox's javascript console reports CSS errors both when the page is
first loaded and when it is re-loaded. The errors reported when the re-
load happens are not the same as when the page is first loaded, but
may still be a consequence. If fixing the CSS so the first errors
don't happen does not stop the errors from being reported during the
re-load then you probably have found a bug in Firefox.

Richard.

Feb 23 '07 #14

P: n/a
On Feb 23, 3:13 pm, "Richard Cornford" <Rich...@litotes.demon.co.uk>
wrote:
On Feb 23, 2:35 pm, DoomedLung wrote:
Richard Cornford wrote:
<snip>
OK heres a working example:http://www.doomeddeveloper.com/newWindowTest.html
Click the link to open a new window then once the new window
has been created refresh the page and you'll see the styles
change...

Firefox's javascript console reports CSS errors both when the page is
first loaded and when it is re-loaded. The errors reported when the re-
load happens are not the same as when the page is first loaded, but
may still be a consequence. If fixing the CSS so the first errors
don't happen does not stop the errors from being reported during the
re-load then you probably have found a bug in Firefox.

Richard.
Hey I just spotted something! Once the new window has been created and
I click on the link (in the newly created window) just once, then
refresh, the styles stay the same!

Feb 23 '07 #15

P: n/a
On Feb 23, 3:42 pm, "DoomedLung" <doomedl...@googlemail.comwrote:
On Feb 23, 3:13 pm, "Richard Cornford" <Rich...@litotes.demon.co.uk>
wrote:
On Feb 23, 2:35 pm, DoomedLung wrote:
Richard Cornford wrote:
<snip>
OK heres a working example:http://www.doomeddeveloper.com/newWindowTest.html
Click the link to open a new window then once the new window
has been created refresh the page and you'll see the styles
change...
Firefox's javascript console reports CSS errors both when the page is
first loaded and when it is re-loaded. The errors reported when the re-
load happens are not the same as when the page is first loaded, but
may still be a consequence. If fixing the CSS so the first errors
don't happen does not stop the errors from being reported during the
re-load then you probably have found a bug in Firefox.
Richard.

Hey I just spotted something! Once the new window has been created and
I click on the link (in the newly created window) just once, then
refresh, the styles stay the same!
I think this may have something to do with caching in FF!!?? But that
is way beyond my scope... :(

Feb 23 '07 #16

This discussion thread is closed

Replies have been disabled for this discussion.