473,385 Members | 2,210 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,385 software developers and data experts.

Positioning problem

Dan
I'm trying to create a menu in javascript. I've created the bitmaps with
text over the top of them. The problem i'm having is that the positions
aren't correct. If I wrap the code in PRE tags, then this fixes it. But
this seems to be a bit of a hack, as apposed to finding what the bug is.
I've included examples of the problem below:

http://dracan.x-1.net/test/index.html (Demonstrates the problem)
http://dracan.x-1.net/test/index2.html (Using the PRE hacky fix)

The actual relevant javascript code is here:

http://dracan.x-1.net/test/menu.js

Thanks for any help,
Dan.
Jul 20 '05 #1
6 2189
"Dan" <da*@nospam.com> writes:
I'm trying to create a menu in javascript. I've created the bitmaps with
text over the top of them. The problem i'm having is that the positions
aren't correct. If I wrap the code in PRE tags, then this fixes it. But
this seems to be a bit of a hack, as apposed to finding what the bug is.
I've included examples of the problem below:

http://dracan.x-1.net/test/index.html (Demonstrates the problem)
http://dracan.x-1.net/test/index2.html (Using the PRE hacky fix)

The actual relevant javascript code is here:

http://dracan.x-1.net/test/menu.js

Thanks for any help,


In your code, you write:
document.writeln (">" + obj_text + "<\DIV>\n");
Notice that it is a "\" in front of the "DIV", not "/" as it should be.
That means that the div's are not terminated, so instead they are all
nested inside each other.

Again saved by the bookmarklet:
javascript:document.body.innerHTML.replace(/&/g,"&amp;").replace(/</g,"&lt;")
:)

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
Dan
Doh! :) Well spotted. What's this bookmarklet thing? I'm fairly new to
javascript (if you hadn't guessed), so i've not heard of it.

Thanks,
Dan.
"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:n0**********@hotpop.com...
"Dan" <da*@nospam.com> writes:
I'm trying to create a menu in javascript. I've created the bitmaps with text over the top of them. The problem i'm having is that the positions
aren't correct. If I wrap the code in PRE tags, then this fixes it. But this seems to be a bit of a hack, as apposed to finding what the bug is.
I've included examples of the problem below:

http://dracan.x-1.net/test/index.html (Demonstrates the problem)
http://dracan.x-1.net/test/index2.html (Using the PRE hacky fix)

The actual relevant javascript code is here:

http://dracan.x-1.net/test/menu.js

Thanks for any help,
In your code, you write:
document.writeln (">" + obj_text + "<\DIV>\n");
Notice that it is a "\" in front of the "DIV", not "/" as it should be.
That means that the div's are not terminated, so instead they are all
nested inside each other.

Again saved by the bookmarklet:

javascript:document.body.innerHTML.replace(/&/g,"&amp;").replace(/</g,"&lt;"
) :)

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'

Jul 20 '05 #3
"Dan" <da*@nospam.com> writes:

What's this bookmarklet thing? I'm fairly new to
javascript (if you hadn't guessed), so i've not heard of it.


A bookmarklet is just a bookmark (what Microsoft calls a "Favorite").
Instead of an URL that points to a new page, it contains Javascript
code. Selecting the bookmark executes the code in the context of the
current page, and possibly replaces it.

In this case:

javascript:document.body.innerHTML.replace(/&/g,"&amp;").replace(/</g,"&lt;")

the bookmarklet shows the HTML code of the actual document, not the
source that generated it with document.write's. With generated code,
it is hard to see the bugs in the code that generates it, but often
easy to see when looking at the actual code.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4
On 07 Oct 2003 15:29:43 +0200
Lasse Reichstein Nielsen <lr*@hotpop.com> wrote:
<snip>
javascript:document.body.innerHTML.replace(/&/g,"&amp;").replace(/</
g,"&lt;")

<snip>

How would you do this without using .innerHTML?

--
Life is an offensive, directed against the repetitious mechanism of the
Universe.
--Alfred North Whitehead (1861-1947)
Jul 20 '05 #5
Albert Wagner <al******@tcac.net> writes:
On 07 Oct 2003 15:29:43 +0200
Lasse Reichstein Nielsen <lr*@hotpop.com> wrote:
<snip>
javascript:document.body.innerHTML.replace(/&/g,"&amp;").replace(/</
g,"&lt;")

<snip>

How would you do this without using .innerHTML?


Much harder :)

I would traverse the DOM document tree and build the corresponding
HTML:

function traverse(node){
if (node.nodeType == 3){
return node.nodeValue.replace(/&/g,"&amp;").replace(/</g,"&lt;"));
}
if (node.nodeType == 1){
var tag="<"+node.tagName;
var attr = node.attributes;
for (var i=0;i<attr.length;i++) {
tag+=" "+attr[i].name+"=\""+attr[i].value+"\"";
}
tag += ">";
for (var chld=node.firstChild;chld;chld=chld.nextSibling) {
tag+=traverse(chld);
}
tag+="<\/"+node.tagName+">";
return tag;
}
return "";
}

You can then use
traverse(document.body).replace(/&/g,"&amp;").
replace(/</g,"&lt;").
replace(/\n/g,"<br>")
to get an HTML representation of the document structure.

To create it as a bookmarklet, you have to includ the function in the
bookmark. That takes some munging to get on one line:

javascript: function traverse(node){ if (node.nodeType == 3){ return node.nodeValue.replace(/&/g,"&amp;").replace(/</g,"&lt;"); } if (node.nodeType == 1){ var tag="<"+node.tagName; var attr = node.attributes;for (var i=0;i<attr.length;i++) { tag+=" "+attr[i].name+"=\""+attr[i].value+"\""; } tag += ">"; for (var chld=node.firstChild;chld;chld=chld.nextSibling) { tag+=traverse(chld); } tag+="<\/"+node.tagName+">"; return tag; } return ""; }traverse(document.body).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/\n/g,"<br>")

This simple code makes end tags for all tags, including </img> and </input>.

It might be too long for some browsers. It works in Opera 7.2, but not
in Mozilla FB and IE. Since they both have innerHTML, it's not that
important. It will never work in Netscape 4, no matter what method is used.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #6
On 07 Oct 2003 17:57:18 +0200
Lasse Reichstein Nielsen <lr*@hotpop.com> wrote:
<snip>
I would traverse the DOM document tree and build the corresponding
HTML:

<snip>

Wow. I am of two minds now. I am sorry that my question involved such
an unexpectedly long response. But I am extremely grateful for your
labor, in that I prefer Opera for development. I think gratitude wins
out, though. Thank you.
--
Life is an offensive, directed against the repetitious mechanism of the
Universe.
--Alfred North Whitehead (1861-1947)
Jul 20 '05 #7

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

Similar topics

12
by: Tom Szabo | last post by:
Hi, Just wondering if there are any disadvantage in absolute positioning controls on a page? In example instead of putting the text fields into a table to align properly, one would absolute...
9
by: Bryan R. Meyer | last post by:
Hello Everyone, The problem of browser resizing has become an issue for me. While redesigning my webpage, I set the left and right margins to be auto so that my content would be centered. ...
4
by: Jane Withnolastname | last post by:
I am trying to re-work an old site by replacing the html with css. On the main page, I have a logo image which I needed centred on the initial screen. I found the solution here:...
14
by: Harlan Messinger | last post by:
What am I not understanding about the definition of { position: absolute; }? "The box's position (and possibly size) is specified with the 'left', 'right', 'top', and 'bottom' properties. These...
6
by: rajek | last post by:
I posted a similar question yesterday, but didn't get an answer that resolved the issue. (Thanks to those who tried though.) The background: I've read in books and online that if you have one...
9
by: Frances Del Rio | last post by:
I have a pg with lots of divs, one of them is a gray bar about 150px down from the top and 20px from the left... this bar (an image) is 767px wide and 1px high.. however, even though all divs are...
11
by: NS | last post by:
I am relativly new to css positioning and have a question regarding the display of a DHTML pop-up Here is the basic HTML I am using: <html> <head> <script language="JavaScript"> <!--
4
by: TheCeej | last post by:
I'm sorry to post what is ultimately a myspace problem, but I'm sure I'd still be having this problem with any html/css document, so the answer would more than likely be able to help anyone out. I'm...
2
by: nino9stars | last post by:
Hello, I have just started messing with absolute positioning on webpages, and it definitely let's you do some creative things. Well, after much searching and help, I got the images I was using...
2
by: TheCruelPanda | last post by:
Hey there. My name is Rowan, and it's been three weeks since I last used tables for an HTML design. Okay, I'm rather new to CSS and I have a big positioning problem here. It might not be a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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:
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...

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.