Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

event.problems with firefox

Status
Not open for further replies.

webmigit

Programmer
Aug 3, 2001
2,027
US
The following code works fine in IE but not in Firefox:

Code:
  document.getElementById('containerFrame').style.left = document.body.scrollLeft + (event.clientX - 5) + 'px';
  document.getElementById('containerFrame').style.top = document.body.scrollTop + (event.clientY - 5) + 'px';
  document.getElementById('containerDiv').style.left = document.body.scrollLeft + (event.clientX - 5) + 'px';
  document.getElementById('containerDiv').style.top = document.body.scrollTop + (event.clientY - 5) + 'px';
  document.getElementById('containerFrame').style.width = document.getElementById('containerDiv').offsetWidth + 'px';
  document.getElementById('containerFrame').style.height = document.getElementById('containerDiv').offsetHeight + 'px';
  document.getElementById('containerDiv').style.display = '';
  document.getElementById('containerFrame').style.display = '';

ContainerDiv is well.. a div.
ContainerFrame is well.. an iFrame.

The following gets the objects to show but does not position correctly.

Code:
//  document.getElementById('containerFrame').style.left = document.body.scrollLeft + (event.clientX - 5) + 'px';
//  document.getElementById('containerFrame').style.top = document.body.scrollTop + (event.clientY - 5) + 'px';
  document.getElementById('containerDiv').style.left = 50;
  document.getElementById('containerDiv').style.top = 50;
  document.getElementById('containerFrame').style.width = document.getElementById('containerDiv').offsetWidth + 'px';
  document.getElementById('containerFrame').style.height = document.getElementById('containerDiv').offsetHeight + 'px';
  document.getElementById('containerDiv').style.display = '';
  document.getElementById('containerFrame').style.display = '';

I tried some ..iffy.. tests (alert(document.getElementById('objectName')); (where objectName was either containerDiv or containerFrame and both returned that its an html element so it is being recognized.

I can't access the event model in firefox, nor use code that other sites say should work. They don't work.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 

You are missing the unit specifier after some of your values.

Dan


The answers you get are only as good as the information you give!

 

You also need to make the two values of 50 into strings, and add units after those, too:

'50px'

I'm sure I said the same thing when you asked yesterday:

thread216-1016410

Hope this helps,
Dan



The answers you get are only as good as the information you give!

 
You did, but that has no effect on the display... 50 shows as well as 50px. The issue is that I need to display the box so that the upper left corner is at the mouse location.

These 4 lines do not work in firefox

Code:
  document.getElementById('containerFrame').style.left = document.body.scrollLeft + (event.clientX - 5) + 'px';
  document.getElementById('containerFrame').style.top = document.body.scrollTop + (event.clientY - 5) + 'px';
  document.getElementById('containerDiv').style.left = document.body.scrollLeft + (event.clientX - 5) + 'px';
  document.getElementById('containerDiv').style.top = document.body.scrollTop + (event.clientY - 5) + 'px';

And it seems to be the event.scope causing the problem.

But thank you for your answer, I'm sure that if I didn't fix it already, I'd have some issue once I figured out the event.problem.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Not sure if this is your problem, but in firefox you need to pass the event to the function like [tt]fName(event)[/tt] then in your function, add a line at the beginning like this:
Code:
if (!event) event = window.event;

Also, you should probably change that last line to accomodate the documentElement
Code:
  document.getElementById('containerDiv').style.top = (document.documentElement) ? document.documentElement.scrollTop + (event.clientY-5) + 'px' : document.body.scrollTop + (event.clientY - 5) + 'px';

hope that helps

"It is the mark of an educated mind to be able to entertain a thought without accepting it." - Aristotle
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top