Facebook的颜色框URL参数 [英] Colorbox URL Params for Facebook Like

查看:103
本文介绍了Facebook的颜色框URL参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通过的问题?和/通过我的url,因为我使用drupal(虽然我认为这并不重要drupal或静态网站)。



每个媒体内容类型我需要一个路径localhost / media / video?open =?cbox10



Pathauto模块针对每种媒体资产内容类型具有此属性。
media / videos?open =?cbox [nid]



节点url看起来像
http:// localhost / media-gallery / images%3Fopen%3D%3Fcbox14



让我知道,如果我错了,但我相信我需要现在编码/解码的url使用php。这些节点网址中的每一个都需要在视频页面上直接打开彩色框。



我正在调查urlEncodeComponent,但不知道如何实现它。我想象它会在我的page.tpl.php和解码时,只要有这些字符的存在。



我可以编码的URL在我的jquery或php ?



如果有人知道路径自动模块,我不使用,请让我知道。我已经试图不替换在别名的URL中的特定字符,但它不能正常工作,因为它仍然显示解码。



我需要此网址编码才能将正确的链接传递到我网页上每个独特内容的开放图表标记。



目前每个视频资源页面都显示以下内容:

 < meta property =og:url content =http:// localhost / media- 
gallery / images%3Fopen%3D%3Fcbox14/>

需要编码到媒体/视频吗?open =?cbox14



Jquery根据唯一资产ID直接打开颜色框

  //颜色框直接链接
//获取url中的cb id或者如果没有找到则设置为false
var colorboxId =(window.location.href.indexOf('open =')== - 1)?
false:
window.location.href.slice(window.location.href.indexOf('open =')+'open ='。length +1).split('&') 0];

//实例化页面上的所有颜色框
$(。colorbox-inline)。

//如果colorbox的id在url中发送,现在打开
if(colorboxId!== false){
$(#+ colorboxId).colorbox {open:true});
}

目前测试...无效:

 < script> 

$(document).ready(function(){
var ogurl = $('meta [property =og:url] [content] );

$(ogurl).prop(content,
decodeURIComponent(ogurl);
});


; / script>

它的作用是什么,但是如何确保我的网址被正确编码感谢这么多!

解决方案



如果你在PHP中编写它,你最好在PHP中解码它。

  < meta property =og:urlcontent ='。urldecode(http:// localhost / media- 
gallery / images%3Fopen%3D%3Fcbox14)。'/& b $ b

否则使用jQuery,但我不知道如果这可以做,因为Facebook执行JavaScript, (例如点击事件)。

  $('meta [property =og:url] [content ]')。each(function(){
$(this).prop(content,decodeURIComponent($(this).prop(content)));
});


I have an issue of passing the ? and = through my url since I am using drupal (although i think it doesn't matter drupal or static site).

Each media content type I have needs a path of localhost/media/video?open=?cbox10

Pathauto module has this for each media asset content type. media/videos?open=?cbox[nid]

The node url then looks like http://localhost/media-gallery/images%3Fopen%3D%3Fcbox14

Let me know if I'm wrong but i believe I need to now encode/decode the url using php. Each of these node urls needs to directly open color box on the videos page.

I was looking into urlEncodeComponent but not sure how to implement it. I imagine it would be in my page.tpl.php and be decoded whenever those characters are present.

Can I possibly encode the value of the URL's within my jquery or php?

If anyone has knowledge of path auto module that I am not utilizing, please let me know. I have already tried to 'not replace' specific characters in my aliased url but its not working as expected, since it still shows up decoded.

I need this url encoded in order to pass the correct link to open graph tags for each unique piece of content on my page.

Currently have this displaying for each video asset page:

<meta property="og:url" content="http://localhost/media-
gallery/images%3Fopen%3D%3Fcbox14" />

which needs to be encoded to media/videos?open=?cbox14

Jquery to directly open color box according to unique asset ID

// Colorbox direct linking
  // Get the cb id in url or set false if not found
    var colorboxId = (window.location.href.indexOf('open=')==-1) ?
        false :
        window.location.href.slice(window.location.href.indexOf('open=') + 'open='.length + 1).split('&')[0];

    // Instantiate all colorboxes on the page
    $(".colorbox-inline").colorbox();

    // If id of colorbox was sent in url, open it now
    if(colorboxId !== false) {
    $("#" + colorboxId).colorbox({open:true});
    }   

Currently Testing...doesn't work:

    <script>

$(document).ready(function() {
    var ogurl = $('meta[property="og:url"][content]').prop("content");

        $( ogurl ).prop("content", 
            decodeURIComponent( ogurl );
});


    </script>

It works for what it is but how can I ensure my url is encoded properly so that facebook og:url can pick up the decoded url.

thanks so much!

解决方案

If you're writing this in PHP you'll better decode it in PHP too.

echo '<meta property="og:url" content="' . urldecode("http://localhost/media-
gallery/images%3Fopen%3D%3Fcbox14") . '" />';

Otherwise use jQuery but I'm not sure if this can be done because Facebook executes JavaScript too and you should maybe modify it for (ex. click event).

$('meta[property="og:url"][content]').each(function() {
    $(this).prop("content", decodeURIComponent($(this).prop("content")));
});

这篇关于Facebook的颜色框URL参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆