www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 27

Thread: Substitute of ping doesn't work properly

  1. #1
    Join Date
    Jul 2012
    Posts
    17

    Substitute of ping doesn't work properly

    Hey, I have problem with code in javascript because I don't know what isn't right. I always get alert says: "there isn't".

    Code:
    <html>
    	<head>
    		
    	</head>
    	<script type="text/javascript">
    		var ImageObject = new Image(); 
    		ImageObject.scr = "http://images.my-addr.com/img/exam_gif_to_png.gif";
    		
    		if(ImageObject.height > 0){ 
    			alert("there is");
    		} else {
    			alert("there isn't");
    		}
    	</script>
    	<body>  
    		
    	</body>
    </html>

  2. #2
    Join Date
    Aug 2012
    Posts
    13
    ImageObject.scr = ImageObject.src

    :P

  3. #3
    Join Date
    Jul 2012
    Posts
    17
    Thanks, but still dosen't work. I have this here: http://fajkowsky.cba.pl/

  4. #4
    Join Date
    Aug 2012
    Posts
    13
    it says 'there is' at my browser.. maybe u need to close and re-open ur browser? or reset cookies/buffer..? Nothing wrong with the script now.

    EDIT: you should devine a Doctype in the head of ur HTML file by the way.. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    Last edited by LukieB; 08-30-2012 at 08:18 AM.

  5. #5
    Join Date
    Jul 2012
    Posts
    17
    On Chrome dosen't work but on Firefox is working.

  6. #6
    Join Date
    May 2012
    Location
    St. Helens, UK
    Posts
    74
    I just tried the code in my own browser and found that it worked (i.e. it returned "there is" when pointed at an image hosted on my laptop's instance of Apache). Clear your cache, and try again.
    Crisialu Web Design
    Daihuws's Blog

    "There is no human problem which could not be solved if people would simply do as I advise."

  7. #7
    Join Date
    Aug 2012
    Posts
    13
    in chrome and safari the image has to be cached before u can use this script to get it's height/width, so u should try to execute this function after the image is printed on the screen.

  8. #8
    Join Date
    Jul 2012
    Posts
    17
    So I can't use this function to do something like ping? Because I want to check if there is internet connection.

  9. #9
    Join Date
    May 2012
    Location
    St. Helens, UK
    Posts
    74
    Quote Originally Posted by LukieB View Post
    in chrome and safari the image has to be cached before u can use this script to get it's height/width, so u should try to execute this function after the image is printed on the screen.
    Ah, I hadn't thought of that! I wonder if it's possible to get JavaScript to parse a file that the browser hasn't previously cached...
    Crisialu Web Design
    Daihuws's Blog

    "There is no human problem which could not be solved if people would simply do as I advise."

  10. #10
    Join Date
    May 2012
    Location
    St. Helens, UK
    Posts
    74
    Faja: have you tried the ideas on this page: http://stackoverflow.com/questions/2...ith-javascript ?
    Crisialu Web Design
    Daihuws's Blog

    "There is no human problem which could not be solved if people would simply do as I advise."

  11. #11
    Join Date
    Aug 2012
    Posts
    13
    Quote Originally Posted by daihuws View Post
    Ah, I hadn't thought of that! I wonder if it's possible to get JavaScript to parse a file that the browser hasn't previously cached...
    You can use the jquery .get function to load stuff in ur cache.

  12. #12
    Join Date
    Jul 2012
    Posts
    17
    But I will be doing this load very often one in 30 minutes. I need somehow to everytime check if there is internet no if there is in chache.

  13. #13
    Join Date
    Aug 2012
    Posts
    13

  14. #14
    Join Date
    May 2012
    Location
    St. Helens, UK
    Posts
    74
    Adapting one of the examples on the Stack Overflow page slightly:

    Code:
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.js"></script>
    <script>if (Boolean(window.jQuery)) {document.write("<h1>INTERNET AVAILABLE! :)</h1>");}
            else {document.write("<h1>INTERNET UNAVAILABLE! :(</h1>");}</script>
    Have just tested it by turning internet off and on and seems to work; although can't guarantee that a cached copy of jQuery won't lead to a false positive.
    Crisialu Web Design
    Daihuws's Blog

    "There is no human problem which could not be solved if people would simply do as I advise."

  15. #15
    Join Date
    Jul 2012
    Posts
    17
    I make a chrome extension and I need this in javascript

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles