473,396 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem with reload

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
15 1738
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Emmanuel | last post by:
Hi, I use a 'reload all' feature in my app, that allow to reload every module. I first try this version : import sys def Reload():
1
by: Ed Blinn | last post by:
Can someone tell me why this script will only work on a Mac with Internet Explorer. Thanks, Ed <html> <head> <script type="text/javascript"> //Square Root
4
by: Clive Moore | last post by:
I have an webpage that opens a child window that displays an applet. When the user calls this function for the second time the same window is opened which is fine except I need the page to be...
4
by: N. Demos | last post by:
Hello, I'm learning ASP.NET, and am having a strange problem with some example code from the book I'm using. The code increments and displays the value stored in a session variable when the "Add"...
42
by: Greg | last post by:
Hi, I've designed a bookmark in Ajax / PHP that I will put soon on sourceforge.net. But I've got an very tricky bug. I try it on some computers with Internet Explorer/Windows, Firefox...
2
by: mayla_i | last post by:
Hello experts I have this question which confuse me! so please help me Is there a difference between clicking on the refresh button in the browser and writing this command:...
0
by: androusm | last post by:
Hi all, I have a problem with reload my servlet with tomcat 5.0.27 My servlet is the one example of the struts "struts-example". I also make changes and want to reload it by tomcat 5.0.27. ...
1
by: gauravtechie | last post by:
Hi all, I have a javascript that is reloading itself on every menu change, Now the problem is that the values of the product doesn`t reset itself on catalogue change, the code is <html>...
0
by: Rafe | last post by:
Hi, This seems to be an old question, and I've read back a bit, but rather than assume the answer is "you can't do that", I'd thought I'd post my version of the question along with a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.