Add to Google

Browser Compatibility Problem With Firefox - Javascript + Css - Having trouble making a script work right - any suggestions?

free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > Others

Browser Compatibility Problem With Firefox - Javascript + Css - Having trouble making a script work right - any suggestions?

minimcmonkey
Hi,
Im working on a website, and im trying to make a right-click menu, which opens on right click, wherever the cursor is, and closes on mouse out.
I wrote the code below, and when i ran it in IE it ran fine, just how i wanted it to work.
However in firefox, the menu just opened in the top left. im presuming this is because it doesnt like my style changing in the javascript.
Any ideas, and suggestions?
If i cant make this work, i will just make it so it works slightly differently when viewev in firefox so that it can just open in one place.

All ideas appreciated.


CODE




<script type="text/javascript">
function coordinates(event)
{
if (event.button==2)
{

var x=event.x-6;
var y=event.y-6;

document.getElementById("element").style.left=x;
document.getElementById("element").style.top=y;
document.getElementById("element").style.visibility="visible";
}
}
</script>

<script type="text/javascript">
function hideme()
{
document.getElementById("element").style.visibility="hidden";
}
</script>

<style type="text/CSS">
#element {
position: absolute;
top: 0px;
left: 0px;
background-color: 568934;
border: 3px dashed;
visibility: hidden;
z-index: 1;
}
</style>
</head>
<body bgcolor="112233" onmousedown="coordinates(event)" oncontextmenu="return false;">

<div id="element" onmouseout="hideme()">
hi<br>
hi<br>
hi<br>
hi<br>
hi<br>
hi<br>
hi<br>
</div>



</body>
</html>




 

 

 


Comment/Reply (w/o sign-up)

shadowx
Im not much of an expert with JS and these sorts of things, i prefer the back end of websites as it were but i have a few ideas. Firstly make it visible in the CSS and view it in FF, does it appear in the right place? If not then you know you have a problem with the CSS and the JS has nothing to do with it, if its in the right place when visible but wrong when the JS gets involved then its the JS.

It could be due to the way FF and IE parse the HTML, as far as i know IE loads the page as one "element" and FF does it line by line, dsiplaying wht it reads as it goes along, so it could be due to that.

But as i said, first thing to try is to see where it is when its visible and work from there.


Comment/Reply (w/o sign-up)

jlhaslip
I know very little javascript, so I can't help you with that, but it appears that FF is placing the div exactly where it is told to by the use of position: absolute.
Check the Dom Console using Firebug extension to confirm that. FF might use something other than style.left and style.top to position the on-click event co-ordinates, too.
If so, you will need to program a conditional if code sequence to check whether FF or IE is being used and then apply the correct coding.

Comment/Reply (w/o sign-up)

Saint_Michael
Thats what I concluded as well haslip, but I have feeling though that it is the javascript itself so I did a little searching and found this script that does what you need and it includes CSS as well. I also included the code down below for quicker retrieval.

HTML
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>My project</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link type="text/css" rel="stylesheet" href="webtoolkit.contextmenu.css" />
<script type="text/javascript" src="webtoolkit.contextmenu.js"></script>
<script type="text/javascript">
SimpleContextMenu.setup({'preventDefault':true, 'preventForms':false});
SimpleContextMenu.attach('container', 'CM1');
</script>
</head>
<body>
<ul id="CM1" class="SimpleContextMenu">
<li><a href="#">Item 1</a></li>
<li><a href="#">Item 2</a></li>
<li><a href="#">Item 3</a></li>
<li><a href="#">Item 4</a></li>
</ul>

<input type="text" name="field" value="" />
<div class="container">Cointainer1</div>
<div class="container">Cointainer2</div>
<div class="container">Cointainer3</div>
</body>
</html>


CSS
CODE
ul.SimpleContextMenu {
    display: none;
    position: absolute;
    margin: 0px;
    padding: 0px;
    font-family: verdana;
    font-size: 12px;
    list-style-type: none;
    border-top: 1px solid #000000;
    border-left: 1px solid #000000;
    border-right: 1px solid #000000;
}

    ul.SimpleContextMenu li {
        border-bottom: 1px solid #000000;
    }

        ul.SimpleContextMenu li a {
            display: block;
            width: 100px;
            padding: 2px 10px 3px 10px;
            text-decoration: none;
            color: #ff0000;
            background: #eeeeee;
        }

        ul.SimpleContextMenu li a:hover {
            text-decoration: none;
            color: #ffffff;
            background: #ff0000;
        }


JAVASCRIPT

CODE
/**
*
* Simple Context Menu
* http://www.webtoolkit.info/
*
**/

var SimpleContextMenu = {

// private attributes
_menus : new Array,
_attachedElement : null,
_menuElement : null,
_preventDefault : true,
_preventForms : true,


// public method. Sets up whole context menu stuff..
setup : function (conf) {

if ( document.all && document.getElementById && !window.opera ) {
SimpleContextMenu.IE = true;
}

if ( !document.all && document.getElementById && !window.opera ) {
SimpleContextMenu.FF = true;
}

if ( document.all && document.getElementById && window.opera ) {
SimpleContextMenu.OP = true;
}

if ( SimpleContextMenu.IE || SimpleContextMenu.FF ) {

document.oncontextmenu = SimpleContextMenu._show;
document.onclick = SimpleContextMenu._hide;

if (conf && typeof(conf.preventDefault) != "undefined") {
SimpleContextMenu._preventDefault = conf.preventDefault;
}

if (conf && typeof(conf.preventForms) != "undefined") {
SimpleContextMenu._preventForms = conf.preventForms;
}

}

},


// public method. Attaches context menus to specific class names
attach : function (classNames, menuId) {

if (typeof(classNames) == "string") {
SimpleContextMenu._menus[classNames] = menuId;
}

if (typeof(classNames) == "object") {
for (x = 0; x < classNames.length; x++) {
SimpleContextMenu._menus[classNames[x]] = menuId;
}
}

},


// private method. Get which context menu to show
_getMenuElementId : function (e) {

if (SimpleContextMenu.IE) {
SimpleContextMenu._attachedElement = event.srcElement;
} else {
SimpleContextMenu._attachedElement = e.target;
}

while(SimpleContextMenu._attachedElement != null) {
var className = SimpleContextMenu._attachedElement.className;

if (typeof(className) != "undefined") {
className = className.replace(/^\s+/g, "").replace(/\s+$/g, "")
var classArray = className.split(/[ ]+/g);

for (i = 0; i < classArray.length; i++) {
if (SimpleContextMenu._menus[classArray[i]]) {
return SimpleContextMenu._menus[classArray[i]];
}
}
}

if (SimpleContextMenu.IE) {
SimpleContextMenu._attachedElement = SimpleContextMenu._attachedElement.parentElement;
} else {
SimpleContextMenu._attachedElement = SimpleContextMenu._attachedElement.parentNode;
}
}

return null;

},


// private method. Shows context menu
_getReturnValue : function (e) {

var returnValue = true;
var evt = SimpleContextMenu.IE ? window.Event : e;

if (evt.button != 1) {
if (evt.target) {
var el = evt.target;
} else if (evt.srcElement) {
var el = evt.srcElement;
}

var tname = el.tagName.toLowerCase();

if ((tname == "input" || tname == "textarea")) {
if (!SimpleContextMenu._preventForms) {
returnValue = true;
} else {
returnValue = false;
}
} else {
if (!SimpleContextMenu._preventDefault) {
returnValue = true;
} else {
returnValue = false;
}
}
}

return returnValue;

},


// private method. shows context menu
_show : function (e) {

SimpleContextMenu._hide();
var menuElementId = SimpleContextMenu._getMenuElementId(e);

if (menuElementId) {
var m = SimpleContextMenu._getMousePosition(e);
var s = SimpleContextMenu._getScrollPosition(e);

SimpleContextMenu._menuElement = document.getElementById(menuElementId);
SimpleContextMenu._menuElement.style.left = m.x + s.x + 'px';
SimpleContextMenu._menuElement.style.top = m.y + s.y + 'px';
SimpleContextMenu._menuElement.style.display = 'block';
return false;
}

return SimpleContextMenu._getReturnValue(e);

},


// private method. Hides context menu
_hide : function () {

if (SimpleContextMenu._menuElement) {
SimpleContextMenu._menuElement.style.display = 'none';
}

},


// private method. Returns mouse position
_getMousePosition : function (e) {

e = e ? e : window.Event;
var position = {
'x' : e.clientX,
'y' : e.clientY
}

return position;

},


// private method. Get document scroll position
_getScrollPosition : function () {

var x = 0;
var y = 0;

if( typeof( window.pageYOffset ) == 'number' ) {
x = window.pageXOffset;
y = window.pageYOffset;
} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
x = document.documentElement.scrollLeft;
y = document.documentElement.scrollTop;
} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
x = document.body.scrollLeft;
y = document.body.scrollTop;
}

var position = {
'x' : x,
'y' : y
}

return position;

}

}

 

 

 


Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

Recent Queries:-
  1. javascript problem in firefox form - 26.82 hr back. (1)
  2. firefox javascript undefined document - 33.66 hr back. (1)
  3. srcelement firefox compatibility - 42.82 hr back. (1)
  4. "style.left in firefox" - 44.27 hr back. (1)
  5. website compatibility with firefox - 58.24 hr back. (1)
  6. firefox trouble with javascript - 87.39 hr back. (1)
  7. firefox problem javascript document element value - 187.30 hr back. (1)
  8. firefox javascript undefined - 246.93 hr back. (1)
  9. firefox style refresh - 269.35 hr back. (1)
Similar Topics

Keywords : browser, compatibility, problem, firefox, javascript, css, trouble, making, script, work, suggestions,

  1. Seeking Help With Javascript
    Need help with drag and drop type script (1)
  2. Redirect If Not Using Firefox
    (4)
    Basically i want a code to redirect people to a different page if they're using anything but
    firefox, there are codes for it but i cant find 1. If anyone can give me a hand it would be
    appreciated!!!....
  3. Download Script
    (5)
    hey all, on my website, i would to link to files that i have created/found. since these files are
    larger than 5mb, and i didn't want to waste my precious 500mb space, i hosted them on fileden,
    an online file storage site allowing hotlinking. an example of a url from this site is:
    http://www.fileden.com/files/2007/10/20/15...some%20file.mp3 so anyway, on one of my pages i would
    like to have a link to one of these files. however, instead of streaming the file as the website
    would normally do for the mp3 extension, i would like to 'force' the save link as /....
  4. Streaming Video Capture On Linux
    this script will download all the stream video using linux mplayer (2)
    i was looking for video capter on linux and i coldent find one so i rote one of my one if you use
    linux then you can try this script and if you need any hep just ask CODE #!/bin/bash #      
    # mplayer auto dump stream script #this script will download all the stream files in the ./zam_list
    files #this script by (mohammed tawfeek) zamaliphe@gmail.com #i have do this to be able to watch
    the video on Linux #if you think it is illegally or some thing just  don't tel me that ha #©
    #bash 6/6/2006 download_folder="./video/" #grep -e HREF ./asx/*.asx > ./list1.tx....
  5. Lightbox Script Variations
    (0)
    When the Web 2.0 and Ajax era kicked the best of the best in programmers started creating scripts of
    various kinds. One of these scripts called Lightbox has one of the biggest impact I have notice, it
    is well customizable to fit various formats, such as images, videos, and even maps. To start off I
    will post a link to the original source of the script, I think. Lightbox The object of this
    script is simple, when a user clicks on a thumbnail version of an image it does smooth transition of
    a pop up image that is larger, usually the original size, and when the user cl....
  6. Ajax - A New Technology
    AJAX relies on Java Script (10)
    Recently i did one of my project using AJAX and i could experience the real advantage of this
    Language , What do you say about that ?....
  7. How Can I Make An Auto-updating Shoutbox Type Script?
    I have a few ideas involving AJAX but im looking for something more.. (6)
    Hi all. Ive just started to experiment with AJAX working with PHP and MYSQL to get data and display
    it and im looking to implement it into a shoutbox similar to the one here on the forums but i have a
    question... i know how to use ajax and JS to refresh the contents of a DIV every few seconds r so
    and that essentially reloads the shoutbox content as the REFRESH button does up there ^^ on the
    shoutbox but i think it silly that it should update every few seconds even if theres no new activity
    so what im looking for is a way of letting my AJAX know when there is a new ent....
  8. Looking For Phpbb Script
    (2)
    Hi Friends, I am new to this phpbb script, I come across some features in some site... In some
    sites, the user should reply to the post to view the hidden content. ... Where can I find this kind
    of scripts or plug-ins... Please reply me in this thread.......
  9. Swf Cd Help Needed Please
    Need assistance with a next/previous page script (1)
    Question is: I have a web page that displays a flash file that zooms and pans, but the next page
    button doesnt work. 1. Can the next page work and load the next or previous numbered file? 2. Does
    it have to have all pages in one file, then it calls the next frame? I can e-mail you the 3
    pages/files directly, firewall wont let me pload them. Thank you....
  10. Playing Flash Movies Without The One-click Activation: Simple Insertion Of Javascript
    (5)
    In the past year or two iternet explorer and other browsers have updated their coding platforms.
    The bad thing is that if you have any flash objects at all within your web page you have to hit the
    space bar or click on the flash object to activate it. Once you activate it, you then can interact
    with the object or the object will then play on the website. I dont like how you have to activate
    the flash player first to interact with it. here is the code to prevent that. Believe me people
    notice how much better the site is after you do this. put under the flash player. ....
  11. How Do I Script A Tutorial Submit Site
    (3)
    I am very interested in learning how to create or start my own tutorial submitt site. What do I
    need to learn ? What do I need to have. Is there a script that can be made up or a software? What
    I would like to do is start my own tutorial submit site. something similar to good-tutorials and or
    pixel2life except those sites are really big and cover many tutoriasl for many different programs.
    Id like to just cover tutorials for maybe a total of 3 to 4 different programs. Im sure I need
    hosting a domain a site and some good forums to get something good going. But t....
  12. Error In Purchased Script
    Help Me? (9)
    Ok well i bought a script off the net and tried uploading it to my server and it gave me this error
    Fatal error: Unable to read 22293 bytes in /home/ancient/public_html/index.php on line 0 so i
    contacted the guy who made the script and he said there was nothing wrong with the script and gave
    me a ftp to his account and told me to upload the it there and it works on there so i tried another
    script from another guy and i get same error you guys know anything about it???? Moving from
    Computinghost > Technical Support to Programming. Edited topic title--"Help with a scr....
  13. How Do I Start Making My Website In Flash
    Can't find tutorials in google :( (11)
    Hey everyone, I began making my website with Firworks, and Dreamweaver. But I really want to know
    how to make a website with Flash. I understand with this program you make 'movies'. I have
    done some tutorials too, and I get that. But what I want to know is, if the content in the different
    pages (like home, contact, links etc.) have to be one movie? Or do you use other programs. Like
    this site below, it's a beautiful site of the Luny Tunes (reggeaton music artistgroup): Luny
    Tunes But is the whole site a 'Movie', or is there some HTML in it as w....
  14. Need Script Please
    need script (4)
    Hey everyone i need a script for a password protected page but not just that i also want and
    registration form with it can n e help....
  15. What Is A News Script?
    Fusion News? Cute News? (1)
    What do news scripts such as Fusion News and Cute News do? Does it provide local news or global
    news or something? Or is it something else?....
  16. Newb @ Programming Seeking Suggestions
    (3)
    Hey all, I'm new to programming and I have a hard time deciding on a cross-platform language
    so I can write for Linux, Macintosh, and Windows. I want to make some basic programs, and if
    possible (as in language support), games. I know that Java is one of them, so is Perl. Please
    reply. Thanks, xboxrulz....
  17. Do U Good At Making Picture
    explain how to do this... (4)
    hey to every picture making wizard.i got a odd picture below yesterday.you will say that the picture
    i uploaded looks common with nothing strange.me too at first.now you should press key CTRL + A
    and notice the picture carefully.what happed,the former picture becomes a beautiful girl,really?i
    dont know how to do this kind of picture.with some software?can you explain...have you ever made
    one? /dry.gif" style="vertical-align:middle" emoid=" ....

    1. Looking for browser, compatibility, problem, firefox, javascript, css, trouble, making, script, work, suggestions,

Searching Video's for browser, compatibility, problem, firefox, javascript, css, trouble, making, script, work, suggestions,




advertisement



Browser Compatibility Problem With Firefox - Javascript + Css - Having trouble making a script work right - any suggestions?