473,387 Members | 1,664 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,387 software developers and data experts.

accessing head section

This may be difficult to understand unless you are familiar with the
design mode feature built into Internet Explorer 5.5+. I used this
feature to develop a browser-based WYSIWYG HTML editor for offline
use, but I have run into a serious problem that I can't solve.

innerHTML and outerHTML access the <body> section of the web page
under construction, but I was able to hack together some javascript to
access the <head> section for the user to insert CSS and scripts from
popup form-based code generators. The problem is I can only access the
<head> section twice. When a third insertion of script or CSS is
attempted, it is placed in the <body> section. Amazingly, this still
works for IE, but it's bad coding and I'm sure it doesn't work in
other browsers.

Here is the first two insertions that work:

function generatecss(){
var html = opener.iView.document.body.outerHTML;
var html_txt = "<html>" + "<head>" + "<style>" +
'<!--a:hover{'+thesheet+'}-->' + "</style>\n";
opener.iView.document.write(html_txt);
}
(iView is an iframe used as an editing window for the page under
construction, 'the sheet' is the form output for CSS hover links. Note
that I ended the insertion at </style> without closing the <head>
tag.)

function metaTag(form){
var html = opener.iView.document.outerHTML;
var html_txt = "<head>" + txt + "</head>" + "<body>" + "Page Content
Begins Here" + "</body>" + "</html>\n";
opener.iView.document.write(html_txt);
}
(txt is the form output for meta tags. Note that I had to add body
text and close the <body> and <html> tags. Otherwise, the iView focus
remains in the (invisible) head section and no content can be added to
the body section.)

After hover link properties and meta tags are added, scripts and CSS
that are directed to the head section in the same way end up in the
body section instead. Any ideas about how I could change the functions
so that any number of CSS and script insertions could be made to the
head section as the page is being designed? I have code generators for
rollover buttons, popup windows etc. that require data in the head.
Jul 23 '05 #1
1 1844
On 1 Jul 2004 20:18:13 -0700, ws*****@acmemail.net (William Starr
Moake) wrote:
innerHTML and outerHTML access the <body> section of the web page
under construction, but I was able to hack together some javascript to
access the <head> section for the user to insert CSS and scripts from
popup form-based code generators. The problem is I can only access the
<head> section twice. When a third insertion of script or CSS is
attempted, it is placed in the <body> section. Amazingly, this still
works for IE, but it's bad coding and I'm sure it doesn't work in
other browsers.


It almost certainly does actually, the HEAD and BODY elements are
almost completely normalised into irrelevance in all UA's

Anyway, just use document.documentElement rather than document.body
when you want to work on the whole document and not just the body.

Jim.

--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 23 '05 #2

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

Similar topics

0
by: James | last post by:
Hi, I am trying to build a shopping cart for my DVD website and am having trouble reading variable over different pages. I have a page that allows the user to add things to their cart and this...
9
by: Sunny | last post by:
Hi, I have cr8ed a javascript function in the head section of a jsp page. <!-- function go(theURL) { alert(theURL); if (theURL!=null){
10
by: Brian W | last post by:
Hi All, I have a web user control that, among other things, provides Print this page, and Email this page functionality I have this script that is to execute on the click of the asp:hyperlinks ...
7
by: | last post by:
What is the beat way to dynamically write/add to the HEAD tag of an ASPX page (the <head runat=server ... is too error prone and not very repeatable)? Thanks.
6
by: Ken Varn | last post by:
I want to add my own custom <STYLE> section in the <HEAD> section of my ASP.NET page within a custom control. Can someone tell me how I can have my custom control add tags to the <HEAD> section of...
0
by: Joergen Bech | last post by:
Fairly new to ASP.NET 1.1. Getting the error below when running application on a web server outside of my control, but only the first time I run it: 1. After a long period of inactivity (or...
3
by: Axel Gallus | last post by:
I wrote a javascript function which should return the html code between a frame's body tag: function load_frame_as_string( Framename ) { var Frame =...
3
by: judy.j.miller | last post by:
Does anyone know why i can't access a form element value using dot notation in firefox, when i'm in a function. Works ok in the body. I'm trying to do this: var FarTemp = faren.temp.value; I...
2
Frinavale
by: Frinavale | last post by:
Hi! I am dynamically generating external .js JavaScript resources to be used with a Tab control I created (using VB.NET). Originally, the JavaScript was written directly into the <head> of the...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.