开发者

What alternative to iframe do you see for me

i have a website where i want to make a facebook like button share to add it to my other (second) website

i want to display how many times its in my second website.

i have this code: [in target website] Wich simply querys and echo the number of times.

<?PHP include('../../includes/conexion.php');

$url = $_get['url'];
 $sql = "SELECT times FROM URLS WHERE url = '$url' ORDER BY nkeeps DESC LIMIT 1";
    $r = mysql_query($sql) or die(mysql_error());
    $n = 0;
    while ($row = mysql_fetch_array($r)) {
        $n = $row['nkeeps']+1;

    }
echo $n;

?>

and then i do: [in source website] i create the button on the bottom with counter(iframe) on the top

$(".keeper").html("<div style='width:50px;float:left;text-align:center;height:50px;'>
                        <div style='width:50px;float:left;height:25px;'>
                           <iframe style='width:49px;color:#444;height:24px;border:1px solid #f6f5f7;overflow:hidden;' src='http://website.com/API/public/keep.php?url="+url+"'></iframe>                   </div>
          开发者_开发技巧             <div style='width:50px;height:50px;float:left;'>
                            <a class='keep_btn' href='#' style='background-color:#006;border:1px solid #f6f5f7;color:white;'>keep</a>
                      </div>
                 </div>");

As you can see, the top div shows how many times through the iframe (i manage myself the URL's thing) But i can't get the 'scroll-like' on the tiny iframe on the right and it never looks like the facebook sharer... :( so i was thinking an alternative to this iFrame, How can i load that piece of content using only JS?

Basically,

This is a design problem. iframe works great. but how can i make look like a normal box?


Well there is a reason why facebook and twitter uses iframes and not AJAX. Ajax doesn't allow to fetch data from different domain. So if your source and target websites are located on different domains you'll have to stick with the iframe. And if your only objection to iframe is how it looks then you should stile it up using css. Iframe could be stiled the same way as any other element, so changing it to div, will not make it any prettier.


Instead of fetching the number with an iframe, fetch it with an Ajax call. Use XHR ($.ajax() in jQuery I think) or use return it as json and fetch it with jsonp.

And you really should use a style sheet. Those inline styles are not... good.


You can use the $.get() to fetch the code via ajax then get at the number in the return code and put into a div.

Something like:

$.get(
   "http://keepyourlinks.com/API/public/keep.php?url=http://new.funcook.com/",  
   function(data) {
      $("div_selector").text($(data).find("selector_for_element_with_count").text());
  }
);

In looking at your code, it may help if you can put some id's on those HTML tags you're working with (ie., the one with the original value, and the new one holding the value). It will make the selectors more simple.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜