Problem with reload

D

DoomedLung

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').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>";
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
 
R

Richard Cornford

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

DoomedLung

<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!!?? :(
 
D

DoomedLung

<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!!??
 
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.
 
A

ASM

DoomedLung a écrit :
With code given : that doesn't open a new window
we are far from styles sheet or not ...
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">

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)
 
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
 
D

DoomedLung

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

Richard Cornford

On Feb 23, 12:21 am, ASM <[email protected]>
wrote:
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.
 
D

DoomedLung

DoomedLung a écrit :


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

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

Richard Cornford

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

DoomedLung

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

Richard Cornford

Richard Cornford wrote:
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.
 
D

DoomedLung

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!
 
D

DoomedLung

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top