473,466 Members | 1,406 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

import stylesheet

Hi all, I hopen a new empty window from js code:
var win =
window.open("","debug","width=500,height=300,modal ,dialog,resizable");
and I add some element to the new window:
win.document.write("<img src="image.gif>");
win.document.write.....

How can I add the stylesheet information of the file x.css
(how and where I must write in the new window the line:
<?xml-stylesheet href="x.css" type="text/css"?> )

thanks

Feb 9 '06 #1
7 2032
VK

stefano wrote:
Hi all, I hopen a new empty window from js code:
var win =
window.open("","debug","width=500,height=300,modal ,dialog,resizable");
and I add some element to the new window:
win.document.write("&lt;img src="image.gif&gt;");
win.document.write.....
Which produces a very strange chunk of code of kind of:

<HTML>
&lt;img src="image.gif&gt;
</HTML>

<HTML> pair is still being added automatically as NN 3.0 thaught
everyone
&lt; and &gt; are being sent as it is, they are not converted into < >

Obviously there is neither place not sense to add a style sheet into
_it_
How can I add the stylesheet information of the file x.css
(how and where I must write in the new window the line:
<?xml-stylesheet href="x.css" type="text/css"?> )


You want to do something - you do it good.

1) Create and save file named blank.html in the most primitive form:
<html>
<head>
<title>Debugger</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
</head>
<body>&nbsp;</body>
</html>

2)
var win =

window.open("blank.html","debug","width=500,height =300,resizable=yes");

with (win.document) {
clear();
open('text/html');
write('<html><head><title>Debugger</title>');
write('<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">');
// here it goes now:
write('<link rel="stylesheet" href="my.css">');
write('</head><body>');
// anything you want to add into your page:
write(MyPageContent);
write('</body></html>');
close()
}

Overall ever since NN 4.x is gone such "from A to Z" usage of
document.write is unnecessary complicated way IMHO. It is easier to
load a page-template and change its parts using DOM methods. Up to you
anyway.

Feb 9 '06 #2
My code come from XSLT and the content of the new window is more than
one image (I can have also text, animation and sound (embed element)).
I can't create and save a file for the scope of the application I'm
working on.
I can't use DOM method because I have a lot of problem with IE (strange
things appens. For example a and b are two sibling but a.paretNode is
different of b.parentNode). I need just to add stylesheet information
if is possible in this way.

Feb 9 '06 #3
VK

stefano wrote:
My code come from XSLT and the content of the new window is more than
one image (I can have also text, animation and sound (embed element)).
I can't create and save a file for the scope of the application I'm
working on.
I can't use DOM method because I have a lot of problem with IE (strange
things appens. For example a and b are two sibling but a.paretNode is
different of b.parentNode). I need just to add stylesheet information
if is possible in this way.


Unfortunately it is not possible. document.write() clears the previous
content if used after load event. And you cannot use it before load
because for that you need to have document.write() statements in the
loading page itself.
If you cannot use DOM then you cannot do it at all.
So the only option is to decide which "can't" you have to change to "I
don't like it but I have to" :-)

I would try DOM first, specially because IE has the least problem with
it, it even has a whole special method createStyleSheet for you.

Try:
win.document.createStyleSheet('myStyles.css');

P.S. I'm suspitious about XSLT you mentioned. The page you open is not
XML+XSLT combo by any chance?

Feb 9 '06 #4
I have a xml document that generate a XHTML document using XSLT. in
this document there are some span element (that contain image, text,
ecc) that are hidden. when I click on some other elements, the content
of a particular span tha was hidden should appear on a new window. The
code of the onclick method I write is:
..
..
var content=document.getElementById("content"); //the content of a
hidden span
var s=content.innerHTML;
var win =
window.open("","debug","width=500,height=300,modal ,dialog,resizable");
win.document.write(s);
win.document.close();

Feb 9 '06 #5
stefano wrote:
I have a xml document that generate a XHTML document using XSLT. in
this document there are some span element (that contain image, text,
ecc) that are hidden. when I click on some other elements, the content
of a particular span tha was hidden should appear on a new window. The
code of the onclick method I write is:
.
.
var content=document.getElementById("content"); //the content of a
hidden span
var s=content.innerHTML;
Are you aware that .innerHTML does not return the actual element content
but what the UA could render of it? Especially it will be _HTML_, not
XHTML.
var win =
window.open("","debug","width=500,height=300,modal ,dialog,resizable");
Thank you for pointing out the `modal' and `dialog' features I did not know
about yet. Note however, that without the UniversalBrowserWrite privilege
`modal' is equivalent to `dependent'.

<URL:http://developer.mozilla.org/en/docs/DOM:window.open>
win.document.write(s);
win.document.close();


You missed win.document.open() before the .write().

<URL:http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-72161170>

However, that would still not write any markup to the popup's document.
There is no XML Processing Instruction, no DOCTYPE declaration, no root
element and no container element. So nothing that the stylesheet's
selectors can match reliably.

You are looking for something similar to the following:

<!-- assuming this is XHTML -->
<script type="text/javascript">
<![CDATA[
...

// to create an HTML document
win.document.write([
'<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
' "http://www.w3.org/TR/html4/strict.dtd">',
'<html>',
' <head>',
' <meta http-equiv="Content-Type"'
+ ' content="text/html; charset=iso-8859-1">',
' <title>meaningful title</title>',
' <link rel="stylesheet" href="http://example.com/x.css"'
+ ' type="text/css">',
' </head>',
' <body>',
' <div><img src="image.gif" alt="alternative content">'
+ s
+ '</div>',
' </body>',
'</html>'
].join("\n"));

// to create an XHTML document
win.document.write([
'<?xml version="1.0" encoding="iso-8859-1"?>',
'<?xml-stylesheet href="http://example.com/x.css" type="text/css"?>',
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
' "http://www.w3.org/TR/xhtml1/dtd/xhtml1-strict.dtd">',
'<html>',
' <head>',
' <title>meaningful title</title>',
' </head>',
' <body>',
' <div><img src="image.gif" alt="alternative content">'
+ s
+ '</div>',
' </body>',
'</html>'
].join("\n"));

...
]]>
</script>

(As you can see there is no need for escaping markup delimiters if you
declare the content of the XHTML `script' element as CDATA. However, it
is recommended to use script elements in XHTML as include only, where you
would not need to declare or escape anything.)

It is important that you specify the full URL of the stylesheet because
the generated content has no (reliable) domain.
HTH

PointedEars
Feb 10 '06 #6
Thomas 'PointedEars' Lahn wrote:
// to create an XHTML document
win.document.write([
'<?xml version="1.0" encoding="iso-8859-1"?>',
'<?xml-stylesheet href="http://example.com/x.css"
type="text/css"?>',
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
' "http://www.w3.org/TR/xhtml1/dtd/xhtml1-strict.dtd">',
'<html>',


Argl. I forgot the namespace and stuff. The last quoted line should be
more like

'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"'
+ ' lang="en">',
PointedEars
Feb 10 '06 #7
I try this:
<xsl:attribute name="onclick">javascript:
..
..
var content=document.getElementById("mycontent");
var s=content.innerHTML;
var loc=window.location.toString().replace(/\/([^\/])*xml/,"");
var win =
window.open("","debug","width=500,height=300,modal ,dialog,resizable");
var lll=loc+"x.css";
win.document.open() ;
win.document.write(
'&lt;?xml version="1.0" encoding="iso-8859-1"?&gt;' +
'&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/dtd/xhtml1-strict.dtd"&gt;'
+
'&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"' + '
lang="en"&gt;' +
' &lt;head&gt;'
+
'&lt;title&gt;meaningful title &lt;/title&gt;'+
'&lt;link type="text/css" rel="stylesheet" href=' +lll +" "+'/&gt;'+
' &lt;/head&gt;'
+
' &lt;body&gt;'+
' &lt;div&gt;'
+ s
+ '&lt;/div&gt;'
+
' &lt;/body&gt;'
+
'&lt;/html&gt;'
);
win.document.close();
..
..

and also this:
<xsl:attribute name="onclick">javascript:
..
..
var content=document.getElementById("mycontent");
var s=content.innerHTML;
var loc=window.location.toString().replace(/\/([^\/])*xml/,"");
var win =
window.open("","debug","width=500,height=300,modal ,dialog,resizable");
var lll=loc+"x.css";
win.document.open() ;
win.document.write(
'&lt;?xml version="1.0" encoding="iso-8859-1"?&gt;' +
'&lt;?xml-stylesheet href='+lll +' '+ 'type="text/css"?&gt;' +
'&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/dtd/xhtml1-strict.dtd"&gt;'
+
'&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"' +
' lang="en"&gt;' +
' &lt;head&gt;'
+
' &lt;title&gt;meaningful title &lt;/title&gt;'+
' &lt;/head&gt;'
+
' &lt;body&gt;'+
' &lt;div&gt;'
+ s
+ '&lt;/div&gt;'
+
' &lt;/body&gt;'
+
'&lt;/html&gt;'
);

win.document.close();
but the stylesheet information of the file x.css are not applied to the
new window.
help please
thanks

Feb 10 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Shiju Rajan | last post by:
Hi, I have one transformation called transform1.xsl. transform1.xsl <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:import href="transform2.xsl"/>...
1
by: bjam | last post by:
Hi, today I was able to abstract out into a separate xsl file a template that I specifically perform a call templates for, this worked with import no problem. However, when trying to do the same...
7
by: steven | last post by:
Which one is better: <link rel="stylesheet" href="style.css" type="text/css" /> or <style type="text/css"> @import url("style.css"); </style>
0
by: atlantis | last post by:
Hi, I have a very strange problem with xsl:import when usig RELATIVE path on AIX 5.2 server. I have two XSL files in the same directory: "ists_xslt3.xsl" and "ists_xslt3_layout.xsl". This...
2
by: Keith Chadwick | last post by:
I have been running some tests with regards to xsl:include and xsl:import with the same results on both and I am wondering if someone can explain this behavior to me! First off the xslt file is...
3
by: teranews | last post by:
My question is this... Is 'LINK'ing a stylesheet required before 'IMPORT'ing another for successful hovering? I have a problem which cropped up with the introduction of IE 7 Beta 2... Yes.....
2
by: alex.iskold | last post by:
Hi, i am having the following problem: A style sheet imports another stylesheet: <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:include...
2
by: flamingmo | last post by:
Hi Everyone, it's my first post, so please be kind... :-) I've had a look through the board and although CSS importing has been covered in quite a few topics, I have what I think is a unique...
1
by: Praveen | last post by:
Have a common function in Javascript which do transform for all .xsl's. XSL object is loaded like this. var xslobj=new ActiveXObject("MSXML2.FreeThreadedDOMDocument.4.0"); xslobj.async = false;...
15
by: maxin | last post by:
Hi, I write a javascript function in xsl (UOMConversion.xsl) as follow: <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <script...
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,...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.