2
A
回答
1
我不是確定你在這裏問的是什麼,但是如果你想避開跨域的JS限制,你總是可以在你的服務器上創建一個PHP頁面(或類似的東西),從另一個域中獲取圖像並將它們作爲本地。
下面是一些jQuery代碼,將圖像對象的src
屬性更改爲sh有一個特定的圖片。比方說,我們要顯示圖像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
然後,在你的PHP頁面,你可以得到的URL並在本地處理圖像。這個PHP經過測試可以工作(需要GD2),假設你傳遞了一個有效的圖像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;
}
?>
相關問題
- 1. 燈箱像腳本在Firefox中的跨域iframe
- 2. IE6,燈箱和IFRAME
- 3. 燈箱和iframe全屏
- 4. 搜索跨域iFrame?
- 5. 跨域iframe問題
- 6. 跨域iframe處理
- 7. 跨域+ iFrame問題
- 8. iframe跨域訪問
- 9. 跨域iframe通信
- 10. js跨域到iframe
- 11. 跨域iframe腳本
- 12. 燈箱用的IFrame上的鏈接
- 13. 跨域的iframe獲取值
- 14. 跨域與iframe的通信
- 15. window.postmessage跨域的嵌套iframe
- 16. 獲取iframe中的iframe JavaScript和跨域
- 17. WordPress的thickbox /燈箱/ fancybox /任何管理
- 18. 如何獲得iframe跨域的高度
- 19. 如何靜音跨域iframe的音頻
- 20. 嵌入infusionsoft窗體/ iframe在燈箱
- 21. AMP iframe是不是AMP燈箱
- 22. Facebook靜態iframe應用燈箱
- 23. 我可以聽任何跨域iframe事件嗎?
- 24. 跨域IFRAME調整大小
- 25. 獲取跨域iframe反饋
- 26. jQuery跨域iframe腳本
- 27. iframe跨域獲取CSS
- 28. 跨域ajax iframe javascript問題
- 29. 跨域iframe插入cookie
- 30. 將HTML跨域注入iframe