Results 1 to 2 of 2

Thread: Javascript not working properly in Chrome and Safari

  1. #1
    Join Date
    Jul 2012
    Posts
    12
    Thanks
    20
    Thanked 0 Times in 0 Posts

    Default Javascript not working properly in Chrome and Safari

    Hey Guys

    I'm trying to display my text through lightbox using getElementbyid().innerHTML for which i'm passing variable from php

    It is working absolutely fine in Firefox, Opera, and IE. But when I open it in Chrome and Safari, my text gets displayed for a second and then disappear or do not get displayed at all.

    Below is my Javascript

    Code:
    function openLightBox(imgsrc, xx){
                
    			document.getElementById('light').style.display='block';
                document.getElementById('fade').style.display='block';
     
                document.getElementById('light-image').src = imgsrc;
    			showUser(xx);
    			
            }
     
            function closeLightBox(){
                //document.getElementById('light-image').innerHTML = '';
                document.getElementById('light').style.display='none';
                document.getElementById('fade').style.display='none';
            }
    		function showUser(str)
    		{
    			if (window.XMLHttpRequest)
    		  	{// code for IE7+, Firefox, Chrome, Opera, Safari
    		  		xmlhttp=new XMLHttpRequest();
    			}
    			else
    			{// code for IE6, IE5
    		  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    			}
    		
    			xmlhttp.onreadystatechange=function()
    			{
    		  		if (xmlhttp.readyState==4 && xmlhttp.status==200)
    		  		{
    		    		document.getElementById("div1").innerHTML=xmlhttp.responseText;
    		  		}
    			}
    		xmlhttp.open("GET","form2.php?q="+str,true);
    		xmlhttp.send();
    		}
    Below is the code through which i'm passing php variable to JS function,

    Code:
    <a onClick="openLightBox('images/<?php echo $imgsrc ?>', '<?php echo $text ?>');" class="enlarge"><img src='images/<?php echo $imgsrc ?>' width="150" height="150" /></a>;
    I know there is no problem with my script as it is working fine in rest of the browsers (except Chrome and Safari).

    Can anyone please help. Thanks in advance!!!!!

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Those browsers will not do a local XMLHttpRequest.

    Put the page up live. If there's still a problem with it, give us a link to it.

    Both Chrome and Safari have good error reporting if you know how to use it. I'm most familiar with Chrome. Right click anywhere on the page. Choose "Inspect Element". Once the inspector is launched, click on the console icon. If there are any errors they will be reported there.


    As a side note, the PHP code should be immaterial. As long as it works in some browsers, it will be the same in all. PHP is server side. However, if the code it produces isn't cross browser, then there can be a problem. It's not with PHP, but with the HTML, javascript, and/or other client side code it produces. These can be checked in the same way that other client side code is checked - with validators for HTML and CSS, and with the browser's script console for javascript.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •