链接预览URL PHP / jQuery

问题描述 投票:-1回答:3

我发现这篇文章https://www.ajaxtown.com/article/facebook-type-link-preview,它展示了如何获得我发现易于理解和适应的链接预览。

然而,当我尝试在我的服务器上运行它时,我从提供的脚本中得不到任何回复,并且响应被扰乱,就像网站本身的演示一样,所有hunky dory都可以工作。

我知道跨站点脚本编写是不是没有,但是有人如何访问网站并搜索数据以执行链接预览等操作。

javascript php jquery
3个回答
1
投票

请使用jQuery参考以下链接获取链接预览

http://embedly.github.io/jquery-preview/demo/

下面是脚本部分

<head>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
  <script src="http://cdn.embed.ly/jquery.embedly-3.0.5.min.js" type="text/javascript"></script>
  <script src="http://cdn.embed.ly/jquery.preview-0.3.2.min.js" type="text/javascript"></script>
  <link rel="stylesheet" href="http://cdn.embed.ly/jquery.preview-0.3.2.css" />
</head>

接下来设置一个允许用户输入链接的简单表单:

<form action="/update" method="POST">
    <input id="url" type="text" name="url"/>

    <!-- Placeholder that tells Preview where to put the selector-->
    <div class="selector-wrapper"></div>
</form>

然后,您需要告诉预览要收听的字段:

<script>
    // Set up preview.
    $('#url').preview({key:'your_embedly_key'})// Sign up for a key: http://embed.ly/pricing
    .on('loading', function () {
        $(this).prop('disabled', true);
        $('form .button').html('<i class="icon-spinner icon-spin"></i>');
    }).on('loaded', function () {
        $(this).prop('disabled', false);
        $('form .button').text('Share');
    })
</script>

0
投票

如果您有服务器,那么最好使用服务器支持的任何语言的本地代理。在AJAX Cross Origin可以找到这种解决方案的好例子


0
投票

虽然为时已晚,但对于未来的访客,我发布这个。它简单而完全独立。请访问此链接https://github.com/mahfuzak08/url2preview

© www.soinside.com 2019 - 2024. All rights reserved.