简体   繁体   中英

Any Lightbox for Cross-Domain Iframe

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

Thankx 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;
 }
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM