开发者

Any Lightbox for Cross-Domain Iframe

Searching alot on this topic but no solution... :( Looking for any lightbox for pictures in Cross Domain Environment

T开发者_如何学运维hankx in Advance.


I'm not sure exactly what you're asking here, but if you're looking to circumvent the cross-domain JS restrictions, you can always create a PHP page (or something similar) on your server that fetches images from another domain and serves them as local.

Here is some jQuery Code to change an image object's src attribute to show a specific picture. Lets say we want to show the image http://www.someotherdomain.com/images/pictureofbacon.png....

var urlStr = 'http://www.someotherdomain.com/images/pictureofbacon.png';

//encode the image's url for passing 
var url_enc = encodeURIComponent(urlStr); 

$('#imageBacon').attr(
    'src', 'http://www.yourdomain.com/getPhoto?url=' + url_enc
); //call your php page, passing to it the encode image url 

Then, in your PHP page, you can get the URL and process the image locally. This PHP is tested to work (requires GD2), assuming you pass it a valid image URL.

getPhoto.php

<?php
    $url = $_REQUEST['url'];
    SendImageToBrowser ($url); 

    function SendImageToBrowser($file){
     $info = getimagesize($file);
  $final_width=$info[0];
  $final_height=$info[1];

     switch ( $info[2] ) {
       case IMAGETYPE_GIF:
         $image = imagecreatefromgif($file);
        break;
       case IMAGETYPE_JPEG:
         $image = imagecreatefromjpeg($file);
        break;
       case IMAGETYPE_PNG:
         $image = imagecreatefrompng($file);
        break;
       default:
         return false;
     }
     imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $final_width, $final_height, $width_old, $height_old);
        $mime = image_type_to_mime_type($info[2]);
        header("Content-type: $mime");
        $output = NULL;

     switch ( $info[2] ) {
       case IMAGETYPE_GIF:
         imagegif($image, $output);
       break;
       case IMAGETYPE_JPEG:
         imagejpeg($image, $output);
       break;
       case IMAGETYPE_PNG:
         imagepng($image, $output);
       break;
       default:
         return false;
     }
     return true;
 }
?>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜