473,507 Members | 5,257 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to modify javascript to work on google chrome and mozilla ?

2 New Member
This code dosen't function properly on google chrome, and mozilla firefox, just on IE. The problem is that, it allways put's the box on the left uppercorner, I need to the box to appear to the place where I clicked it. So if anybody could help me with the move_box function, I would really appreciate.

Expand|Select|Wrap|Line Numbers
  1. function move_box(an, box)
  2.  
  3. {
  4.  
  5.     var cleft = 0;
  6.  
  7.     var ctop = 0;
  8.  
  9.     var obj = an;
  10.  
  11.  
  12.  
  13.     while (obj.offsetParent)
  14.  
  15.     {
  16.  
  17.         cleft += obj.offsetLeft;
  18.  
  19.         ctop += obj.offsetTop;
  20.  
  21.         obj = obj.offsetParent;
  22.  
  23.     }
  24.  
  25.  
  26.  
  27.     box.style.left = cleft + 'px';
  28.  
  29.  
  30.  
  31.     ctop += an.offsetHeight + 8;
  32.  
  33.  
  34.  
  35.     // Handle Internet Explorer body margins,
  36.  
  37.     // which affect normal document, but not
  38.  
  39.     // absolute-positioned stuff.
  40.  
  41.     if (document.body.currentStyle &&
  42.  
  43.         document.body.currentStyle['marginTop'])
  44.  
  45.     {
  46.  
  47.         ctop += parseInt(document.body.currentStyle['marginTop']);
  48.  
  49.     }
  50.  
  51.  
  52.  
  53.     box.style.top = ctop + 'px';
  54.  
  55. }
  56.  
  57.  
  58.  
  59. // Shows a box if it wasn't shown yet or is hidden
  60.  
  61. // or hides it if it is currently shown
  62.  
  63. function show_hide_box(an, width, height, borderStyle)
  64.  
  65. {
  66.  
  67.     var href = an.href;
  68.  
  69.     var boxdiv = document.getElementById(href);
  70.  
  71.  
  72.  
  73.     if (boxdiv != null)
  74.  
  75.     {
  76.  
  77.         if (boxdiv.style.display=='none')
  78.  
  79.         {
  80.  
  81.             // Show existing box, move it
  82.  
  83.             // if document changed layout
  84.  
  85.             move_box(an, boxdiv);
  86.  
  87.             boxdiv.style.display='block';
  88.  
  89.  
  90.  
  91.             bringToFront(boxdiv);
  92.  
  93.  
  94.  
  95.             // Workaround for Konqueror/Safari
  96.  
  97.             if (!boxdiv.contents.contentWindow)
  98.  
  99.                 boxdiv.contents.src = href;
  100.  
  101.         }
  102.  
  103.         else
  104.  
  105.             // Hide currently shown box.
  106.  
  107.             boxdiv.style.display='none';
  108.  
  109.         return false;
  110.  
  111.     }
  112.  
  113.  
  114.  
  115.     // Create box object through DOM
  116.  
  117.     boxdiv = document.createElement('div');
  118.  
  119.  
  120.  
  121.     // Assign id equalling to the document it will show
  122.  
  123.     boxdiv.setAttribute('id', href);
  124.  
  125.  
  126.  
  127.     boxdiv.style.display = 'block';
  128.  
  129.     boxdiv.style.position = 'absolute';
  130.  
  131.     boxdiv.style.width = width + 'px';
  132.  
  133.     boxdiv.style.height = height + 'px';
  134.  
  135.     boxdiv.style.border = borderStyle;
  136.  
  137.     boxdiv.style.textAlign = 'right';
  138.  
  139.     boxdiv.style.padding = '4px';
  140.  
  141.     boxdiv.style.background = '#FFFFFF';
  142.  
  143.     document.body.appendChild(boxdiv);
  144.  
  145.     bringToFront(boxdiv);
  146.  
  147.  
  148.  
  149.     var offset = 0;
  150.  
  151.  
  152.  
  153.     // Remove the following code if 'Close' hyperlink
  154.  
  155.     // is not needed.
  156.  
  157.     var close_href = document.createElement('a');
  158.  
  159.     close_href.href = 'javascript:void(0);';
  160.  
  161.     close_href.onclick = function()
  162.  
  163.         { show_hide_box(an, width, height, borderStyle); }
  164.  
  165.     close_href.appendChild(document.createTextNode('Close'));
  166.  
  167.     boxdiv.appendChild(close_href);
  168.  
  169.     offset = close_href.offsetHeight;
  170.  
  171.     // End of 'Close' hyperlink code.
  172.  
  173.  
  174.  
  175.     var contents = document.createElement('iframe');
  176.  
  177.     //contents.scrolling = 'no';
  178.  
  179.     contents.overflowX = 'hidden';
  180.  
  181.     contents.overflowY = 'scroll';
  182.  
  183.     contents.frameBorder = '0';
  184.  
  185.     contents.style.width = width + 'px';
  186.  
  187.     contents.style.height = (height - offset) + 'px';
  188.  
  189.  
  190.  
  191.     boxdiv.contents = contents;
  192.  
  193.     boxdiv.appendChild(contents);
  194.  
  195.  
  196.  
  197.     move_box(an, boxdiv);
  198.  
  199.  
  200.  
  201.     if (contents.contentWindow)
  202.  
  203.         contents.contentWindow.document.location.replace(
  204.  
  205.             href);
  206.  
  207.     else
  208.  
  209.         contents.src = href;
  210.  
  211.  
  212.  
  213.     // The script has successfully shown the box,
  214.  
  215.     // prevent hyperlink navigation.
  216.  
  217.     return false;
  218.  
  219. }
  220.  
  221.  
  222.  
  223. function getAbsoluteDivs()
  224.  
  225. {
  226.  
  227.     var arr = new Array();
  228.  
  229.     var all_divs = document.body.getElementsByTagName("DIV");
  230.  
  231.     var j = 0;
  232.  
  233.  
  234.  
  235.     for (i = 0; i < all_divs.length; i++)
  236.  
  237.         if (all_divs.item(i).style.position=='absolute')
  238.  
  239.         {
  240.  
  241.             arr[j] = all_divs.item(i);
  242.  
  243.             j++;
  244.  
  245.         }
  246.  
  247.  
  248.  
  249.     return arr;
  250.  
  251. }
  252.  
  253.  
  254.  
  255. function bringToFront(obj)
  256.  
  257. {
  258.  
  259.     if (!document.getElementsByTagName)
  260.  
  261.         return;
  262.  
  263.  
  264.  
  265.     var divs = getAbsoluteDivs();
  266.  
  267.     var max_index = 0;
  268.  
  269.     var cur_index;
  270.  
  271.  
  272.  
  273.     // Compute the maximal z-index of
  274.  
  275.     // other absolute-positioned divs
  276.  
  277.     for (i = 0; i < divs.length; i++)
  278.  
  279.     {
  280.  
  281.         var item = divs[i];
  282.  
  283.         if (item == obj ||
  284.  
  285.             item.style.zIndex == '')
  286.  
  287.             continue;
  288.  
  289.  
  290.  
  291.         cur_index = parseInt(item.style.zIndex);
  292.  
  293.         if (max_index < cur_index)
  294.  
  295.         {
  296.  
  297.             max_index = cur_index;
  298.  
  299.         }
  300.  
  301.     }
  302.  
  303.  
  304.  
  305.     obj.style.zIndex = max_index + 1;
  306.  
  307. }
  308.  
Dec 9 '11 #1
3 2593
drhowarddrfine
7,435 Recognized Expert Expert
This will be difficult to figure out without the HTML. Do you have this on the web or can you make a jsfiddle?

In any case, though IE is showing what you want, Firefox and Chrome will show what you wrote. Never, ever use IE as a reference for how things work.
Dec 9 '11 #2
leutrim
2 New Member
Thank you for replying.
Yes I have this on web, here is the whole html and javascript code. The two pictures, Qyteti.jpg and you.jpg, I can send it to you, if necessary.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="mapguide1._Default" %>
  3.  
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  5.  
  6. <html xmlns="http://www.w3.org/1999/xhtml" >
  7. <head runat="server">
  8. <script src="popup.js" type="text/javascript"></script>
  9. </head>
  10.  
  11. <body >
  12.  
  13.  
  14.   <img src="Qyteti.jpg" width="1500" height="1500" alt="Harta" usemap="#citymap" />
  15.  
  16.   <map name="citymap">
  17.  
  18.   <area shape="rect" coords="0,0,600,600" href="you.jpg" onclick="return show_hide_box(this, 200, 270, '2px solid')" alt="LE" />
  19.   <area shape="rect" coords="650,650,1200,1200" href="you.jpg" onclick="return show_hide_box(this, 200, 270, '2px solid')" alt="LE" />
  20.  
  21.  
  22.   </map>
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.    <script type="text/javascript">
  31. // Moves the box object to be directly beneath an object.
  32. function move_box(an, box){  
  33.  var cleft = 0; 
  34.  var ctop = 0;   
  35.  var obj = an;  
  36.   while (obj.offsetParent)    {   
  37.     cleft += obj.offsetLeft;    
  38.     ctop += obj.offsetTop;    
  39.     obj = obj.offsetParent;    }
  40.  
  41.   box.style.left = cleft + 'px';  
  42.   ctop += an.offsetHeight + 8;   
  43.  
  44.  // Handle Internet Explorer body margins, 
  45.  // which affect normal document, but not 
  46.  // absolute-positioned stuff.   
  47.  
  48.  if (document.body.currentStyle &&        document.body.currentStyle['marginTop'])    {        
  49.  
  50. ctop += parseInt(document.body.currentStyle['marginTop']);    }    
  51.  
  52. box.style.top = ctop + 'px';}
  53.  
  54.  
  55.  
  56.  
  57. // Shows a box if it wasn't shown yet or is hidden
  58. // or hides it if it is currently shownfunction 
  59.  
  60. show_hide_box(an, width, height, borderStyle){  
  61.  var href = an.href;   
  62.  var boxdiv = document.getElementById(href);  
  63.  if (boxdiv != null) {     
  64.    if (boxdiv.style.display=='none')  {        
  65.  
  66.     // Show existing box, move it       
  67.      // if document changed layout      
  68.  
  69.       move_box(an, boxdiv);               boxdiv.style.display='block';            bringToFront(boxdiv);         
  70.  
  71.    // Workaround for Konqueror/Safari        
  72.  
  73.     if (!boxdiv.contents.contentWindow)   
  74.  
  75.           boxdiv.contents.src = href;        }        else         
  76.  
  77.    // Hide currently shown box.            
  78.  
  79. boxdiv.style.display='none';     
  80.    return false;    } 
  81.  
  82.    // Create box object through DOM 
  83.    boxdiv = document.createElement('div');   
  84.  
  85.  // Assign id equalling to the document it will show 
  86.  
  87.   boxdiv.setAttribute('id', href);     
  88.   boxdiv.style.display = 'block';  
  89.   boxdiv.style.position = 'absolute';     
  90.   boxdiv.style.width = width + 'px';     
  91.   boxdiv.style.height = height + 'px';    
  92.   boxdiv.style.border = borderStyle;    
  93.   boxdiv.style.textAlign = 'right';    
  94.   boxdiv.style.padding = '4px';  
  95.   boxdiv.style.background = '#FFFFFF';    
  96.   document.body.appendChild(boxdiv);    
  97.   bringToFront(boxdiv);    var offset = 0;   
  98.  
  99.  // Remove the following code if 'Close' hyperlink    // is not needed.   
  100.  
  101.  var close_href = document.createElement('a');     
  102.  close_href.href = 'javascript:void(0);';     
  103.  close_href.onclick = function()        { 
  104.  
  105. show_hide_box(an, width, height, borderStyle); }  
  106.   close_href.appendChild(document.createTextNode('Close'));  
  107.   boxdiv.appendChild(close_href); 
  108.   offset = close_href.offsetHeight;  
  109.  
  110.   // End of 'Close' hyperlink code.    var contents = document.createElement('iframe');    
  111.  
  112. //contents.scrolling = 'no';  
  113.   contents.overflowX = 'hidden';  
  114.   contents.overflowY = 'scroll'; 
  115.   contents.frameBorder = '0';   
  116.   contents.style.width = width + 'px';     
  117.   contents.style.height = (height - offset) + 'px';       
  118.   boxdiv.contents = contents;    
  119.   boxdiv.appendChild(contents);  
  120.  
  121.   move_box(an, boxdiv);   
  122.  
  123.   if (contents.contentWindow)           
  124.    contents.contentWindow.document.location.replace(            href);   
  125.  
  126.  else        contents.src = href; 
  127.  
  128.   // The script has successfully shown the box,   
  129.  // prevent hyperlink navigation.  
  130.  
  131.   return false;}
  132.  
  133. function getAbsoluteDivs(){   
  134.  var arr = new Array();   
  135.  var all_divs =  
  136.  document.body.getElementsByTagName("DIV");   
  137.  var j = 0;  
  138.  for (i = 0; i < all_divs.length; i++)  
  139.  
  140.       if (all_divs.item(i).style.position=='absolute')        {            arr[j] = all_divs.item(i);    
  141.         j++;        }  
  142.   return arr;}
  143.  
  144. function bringToFront(obj){   
  145.  if (!document.getElementsByTagName)    
  146.     return;    var divs = getAbsoluteDivs(); 
  147.    var max_index = 0;   
  148.    var cur_index;   
  149.  
  150. // Compute the maximal z-index of  
  151. // other absolute-positioned divs   
  152.  
  153.  for (i = 0; i < divs.length; i++)    {  
  154.       var item = divs[i];  
  155.       if (item == obj || item.style.zIndex == '')            continue;    
  156.     cur_index = parseInt(item.style.zIndex);    
  157.     if (max_index < cur_index)        {            max_index = cur_index;        }    }   
  158.  
  159.  obj.style.zIndex = max_index + 1;}</script>
  160.  
  161. </body>
  162. </html>
  163.  
  164.  
Dec 10 '11 #3
drhowarddrfine
7,435 Recognized Expert Expert
In your css, you have the body's margin set to zero and the modern browsers are honoring that. IE is not. I haven't looked to see why yet.

EDIT: Got distracted. That's not the main issue. Look at the error in the error console.
Dec 10 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1511
by: James | last post by:
I've been looking at the Mozilla source (1.8b1) and I thought that there I might find definitions of the various client-side JavaScript objects (e.g. history, navigator). Has anyone managed to...
1
2052
by: Guy Macon | last post by:
Serious Security Flaw in Google Chrome: http://www.readwriteweb.com/archives/security_flaw_in_google_chrome.php -- Guy Macon <http://www.GuyMacon.com/>
0
6092
by: wpjoju | last post by:
i have this code which adds an event listener to a newly opened window but it doesn't seem to work in google chrome. the problem is window.addEventListener seem to work in chrome but if you do...
0
1818
by: catoblepa80 | last post by:
How can i read all google chrome bookmarks and place it into a list or a dictionary? i think the best way is to use regular expressions on the chrome bookmarks file, can you help me to accomplish...
2
5284
KeredDrahcir
by: KeredDrahcir | last post by:
When using an object tag to embed a video file everything looks fine in Internet Explorer and Safari. However I can't get it to display at all in Opera. More importantly in Firefox and Google Chrome...
5
6720
by: su817200 | last post by:
Dear Friend, Could you please let me know, how to enable ActiveX controls in Google Chrome Internet Browser. Is there any patch we need to install. Please let me know. Rgds,
3
3048
KeredDrahcir
by: KeredDrahcir | last post by:
Can anyone help me. I don't know if this is a mysql, php or Google Chrome error. I have a login form but for some reason I'm getting an error when I use Google Chrome. It used to work in all...
0
7313
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
7372
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...
0
5619
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5039
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3190
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1537
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.