Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9157569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:03:06+00:00 2026-06-17T13:03:06+00:00

I have tried many of the solutions using javascript to detect broken images but

  • 0

I have tried many of the solutions using javascript to detect broken images but it doesn’t seem to work. Any idea what I’m doing wrong?

Select ‘jquery’ from the dropdown box here to see the broken images:-

http://www.api.jonathanlyon.com/getpocket/view.html

The code for the site is here:-

    <!doctype html>
<html>
<head>
    <meta charset=utf-8>
    <title>Insights Lab</title>
<link href='http://fonts.googleapis.com/css?family=Roboto+Condensed' rel='stylesheet' type='text/css'>  
    <style>
    ul li { color: red;}
    .emphasis { color: green;}
    .code {color: #3387B5}
    body { font-family: 'Roboto Condensed', sans-serif; }
p { font-size: 14px; color:#999; }
h2 { font-size: 18px; 
color:#666;
}
.view {
  bottom: 10;
  height: 16px;
  position: absolute;
}
    #art {
      position: relative;
    width:220px;
    border: 1px solid #999;
    float:left;
    margin-right:10px;
    padding:5px;
    height:300px;
    margin-bottom:8px;
    background-color: #EEEEEE;
    }
    </style>
<script language="JavaScript" type="text/javascript">
function onImgErrorSmall(source)
{
source.src = "http://www.forbes.com/favicon.ico";
// disable onerror to prevent endless loop
source.onerror = "";
return true;
}

function onImgErrorLarge(source)
{
source.src = "http://www.forbes.com/favicon.ico";
// disable onerror to prevent endless loop
source.onerror = "";
return true;
}
</script>
</head>
<body>

<?php

function baseurl($url) {

// you can add more to it if you want
$urlMap = array('com', 'co.uk','it','org','net','ca','io','me','edu','ac.uk','info','au');

$host = "";
//$url = "http://www.google.co.uk";

$urlData = parse_url($url);
$hostData = explode('.', $urlData['host']);
$hostData = array_reverse($hostData);

if(array_search($hostData[1] . '.' . $hostData[0], $urlMap) !== FALSE) {
  $host = $hostData[2] . '.' . $hostData[1] . '.' . $hostData[0];
} elseif(array_search($hostData[0], $urlMap) !== FALSE) {
  $host = $hostData[1] . '.' . $hostData[0];
}

return $host;

}
function highlight($text, $words) {
    preg_match_all('~\w+~', $words, $m);
    if(!$m)
        return $text;
    $re = '~\\b(' . implode('|', $m[0]) . ')\\b~i';
    return preg_replace($re, '<span class="code">$0</span>', $text);
}

$q=$_GET["q"];

$con = mysql_connect('mysql.site.com','un','pw');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("getpocket", $con);

$sql="SELECT * FROM `articles` WHERE `given_title` like '%".$q."%' or `excerpt` like '%".$q."%' order by `time_added` desc";



$result = mysql_query($sql);



while($row = mysql_fetch_array($result))
  {
  $tit = highlight($row['given_title'], $q);
  $exc = highlight($row['excerpt'], $q);
  $url = $row['resolved_url'];
  ?> 
    <div id = "art">
    <h2><?php echo $tit;?></h2>
    <p><?php echo $exc;?></p>

    <div class = "view">

    <a href ="<?php echo $url;?>" target='_blank'><img src = "http://<?php echo baseurl($url);?>/favicon.ico" height="16" width="16" onerror="onImgErrorSmall(this)"></a>
    </div>
    </div>
<?php
}
mysql_close($con);
?> 

</body>
</html>

Any ideas what I’m doing wrong?

Thanks

Jonathan

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:03:08+00:00Added an answer on June 17, 2026 at 1:03 pm

    add this before </body>

    <script>
        function onImgErrorLarge(orig_img) {
            var img = new Image();
    
            img.src =  orig_img.src;
    
            img.onerror = function() {
                orig_img.src = 'other source';
                //alert('Img not found');
            };
        }
    
    
    
    function showUser(str) {
        if (str=="") {
            document.getElementById("txtHint").innerHTML="";
            return;
        }
        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("txtHint").innerHTML=xmlhttp.responseText;
    
                var imgs = document.getElementsByTagName('img');
    
                for(var i = 0; i < imgs.length; i++) 
                   onImgErrorLarge(imgs[i]);
            }
        }
        xmlhttp.open("GET","getarticles.php?q="+str,true);
        xmlhttp.send();
    }
    
    
    
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This should be really simple, but I have tried many solutions posted on the
I have tried many permutations but they all don't seems to work well. Am
Yes, I have searched and tried many techniques, but nothing seems to work. Here
I have tried many options mentioned in the previous messages/forums.None of them seem to
Hello friends I have tried many times but I am not successful than please
I want to get the page rank for any website. I have tried many
I have tried so many things, cannot figure this out, I am using this
I am using jQuery fullcalendar plugin , I have tried altering this many different
I tried many ways to solve this problem but none works. suppose I have
Raking my brain and I have tried many of the solutions found online. Basically

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.