document.body.insertAdjacentHTML - need firefox alternative!

Discuss how to use and promote Web standards with the Mozilla Gecko engine.
AustinBrock
Guest

document.body.insertAdjacentHTML - need firefox alternative!

Post by AustinBrock »

This is the code used to generate the html box window thing....

---------------------------------------------------------

<SCRIPT>

function XY(e)
{
var x = 0;
var y = 0;
if (e.pageX || e.pageY)
{
x = e.pageX;
y = e.pageY;
}
else if (e.clientX || e.clientY)
{
x = e.clientX + document.body.scrollLeft;
y = e.clientY + document.body.scrollTop;
}
// posx and posy contain the mouse position relative to the document
// Do something with this information
}

function ShowMessage(text,id)
{
var popup;
top_pos = y - 120 + 'px';
left_pos = x -100 + 'px';
document.body.insertAdjacentHTML('BeforeEnd', '<DIV><table>' + text + '</table></DIV>');
}

function Kill(id)
{
id.innerHTML = "";
id.outerHTML = "";
}

</SCRIPT>

---------------------------------------------------------

This code is used on each URL that requires a pop up.

---------------------------------------------------------

<A HREF="game.php?id=2">1830: Railroads & Robber Barons</a>

---------------------------------------------------------

But it doesn't work in Firefox, only IE and Opera.

Is there a way of making this work for Firefox as well?

Please help, thanks in advance.
User avatar
trolly
Moderator
Posts: 39851
Joined: August 22nd, 2005, 7:25 am

Post by trolly »

Best to register and ask in the web developer forum. The thread can be moved to that forum.
Think for yourself. Otherwise you have to believe what other people tell you.
A society based on individualism is an oxymoron. || Freedom is at first the freedom to starve.
Constitution says: One man, one vote. Supreme court says: One dollar, one vote.
Guest
Guest

Post by Guest »

insertAdjacentHTML simply isn't a supported function. Add this to your script:
// insertAdjacentHTML(), insertAdjacentText() and insertAdjacentElement
()
// for Netscape 6/Mozilla by Thor Larholm me@jscript.dk
// Usage: include this code segment at the beginning of your document
// before any other Javascript contents.

if(typeof HTMLElement!="undefined" && !
HTMLElement.prototype.insertAdjacentElement){
HTMLElement.prototype.insertAdjacentElement = function
(where,parsedNode)
{
switch (where){
case 'beforeBegin':
this.parentNode.insertBefore(parsedNode,this)
break;
case 'afterBegin':
this.insertBefore(parsedNode,this.firstChild);
break;
case 'beforeEnd':
this.appendChild(parsedNode);
break;
case 'afterEnd':
if (this.nextSibling)
this.parentNode.insertBefore(parsedNode,this.nextSibling);
else this.parentNode.appendChild(parsedNode);
break;
}
}

HTMLElement.prototype.insertAdjacentHTML = function
(where,htmlStr)
{
var r = this.ownerDocument.createRange();
r.setStartBefore(this);
var parsedHTML = r.createContextualFragment(htmlStr);
this.insertAdjacentElement(where,parsedHTML)
}


HTMLElement.prototype.insertAdjacentText = function
(where,txtStr)
{
var parsedText = document.createTextNode(txtStr)
this.insertAdjacentElement(where,parsedText)
}
}[/code] http://www.faqts.com/knowledge_base/view.phtml/aid/5756
Guest
Guest

Re: document.body.insertAdjacentHTML - need firefox alternat

Post by Guest »

No need for a table element, is there?

Code: Select all

function ShowMessage(text,id)
{
 var popup;
  top_pos = y - 120 + 'px';
  left_pos = x -100 + 'px';
  div = document.createElement('div');
  div.innerHTML = text;
  document.body.appendChild('div');
}


Can you provide a link to a working example?
AustinBrock
Guest

Post by AustinBrock »

document.body.insertAdjacentHTML('BeforeEnd', '<DIV><table>' + text + '</table></DIV>');

Thats my document.body.insertAdjacentHTML

Each popup is defined by the tracks it'll list "popup<id>" and it complains they're undefined.

It also complains about y being undefined, even though x is done in the same way.

Help meeee :P!
AustinBrock
Guest

Post by AustinBrock »

:(
old np
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post by old np »

I'll move it. Threads just get buried in this forum. You'll have to register.
AustinBrock
Posts: 7
Joined: August 9th, 2006, 6:04 am

Post by AustinBrock »

I've registered thanks NP.

Anyone got any time to help me out with this please? It's a hassle to learn this javascript when I normally don't touch it.
old np
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Re: document.body.insertAdjacentHTML - need firefox alternat

Post by old np »

This doesn't work?
Anonymous wrote:

Code: Select all

function ShowMessage(text,id)
{
 var popup;
  top_pos = y - 120 + 'px';
  left_pos = x -100 + 'px';
  div = document.createElement('div');
  div.innerHTML = text;
  document.body.appendChild('div');
}
AustinBrock
Posts: 7
Joined: August 9th, 2006, 6:04 am

Post by AustinBrock »

http://www.hoverrace.com/tracks/index.p ... wse&type=5

Hover over the links, theres a working example in IE, but it doesn't work in Firefox.
old np
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Re: document.body.insertAdjacentHTML - need firefox alternat

Post by old np »

np wrote:This doesn't work?
Anonymous wrote:

Code: Select all

function ShowMessage(text,id)
{
 var popup;
  top_pos = y - 120 + 'px';
  left_pos = x -100 + 'px';
  div = document.createElement('div');
  div.innerHTML = text;
  document.body.appendChild('div');
}
AustinBrock
Posts: 7
Joined: August 9th, 2006, 6:04 am

Post by AustinBrock »

I've tried it np, complains about popup being undefined and some other things.

I'm a n00b on these things anyway :(.
old np
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post by old np »

In your mouseout events, put popup in single quotes. Change the following functions

Code: Select all

function ShowMessage(text,id)
{
  top_pos = y - 120 + 'px';
  left_pos = x -100 + 'px';
  div = document.createElement('div');
  div.setAttribute("id", id);
  div.innerHTML = text;
  document.body.appendChild('div');
}

   function Kill(id)
   {
      document.body.removeChild(document.getElementById(id));
   }

and take out the "insertAdjacentHTML(), insertAdjacentText() and insertAdjacentElement()" stuff that the guest above gave you.
AustinBrock
Posts: 7
Joined: August 9th, 2006, 6:04 am

Post by AustinBrock »

Ok, think i did that, but it doesn't work in either now, complains popup is undefined :(

Also has a spaz in the javascript console for firefox.
old np
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post by old np »

Sorry, had some extra quotes. Change

Code: Select all

  document.body.appendChild('div'); 

to

Code: Select all

  document.body.appendChild(div); 

It's still complaining about popup because you didn't change the mouseout events.
Change

Code: Select all

 onmouseout=Kill(popup) 
to

Code: Select all

 onmouseout="Kill('popup')" 
Post Reply