2013-01-09 95 views
0

我必须创建一个灯箱并在其中打开外部网址的内容。 我不允许更改现有的代码。在这一刻,它是一个简单的链接到页面,现在将不得不载入一个灯箱。在灯箱中打开外部网址

我必须自己写所有的代码,所以没有像colorbox这样的插件。 我知道如何打开/关闭灯箱。只是无法弄清楚如何在那里加载外部网址的内容。

我希望你们能帮助我:)提前

回答

5

感谢我认为你应该使用负载(jQuery的)的方法。借助该方法,您可以从其他网址获取内容,并将其作为HTML添加到您的灯箱中。

$('#idofDiv').load('test.html', function() { 
    alert('Load was performed.'); 
}); 

http://api.jquery.com/load/

+1

我认为URL是不完整的 'eepurl.com/q4rPD' 和不应该有; –

+0

对不起,我输错了网址。但是我犯了一个错误。我想从我的评论中拿出网址,但意外地保留了大部分内容。 – Weszzz7

+0

是的jQuery加载方法与相同的域名。所以你应该在你的ligtbox中放入一个iframe,然后用jquery更改它的src –

-1
Lightbox 2 uses the jQuery framework. Load jQuery and the Lightbox javascript files in the proper order. 

<script src="js/jquery-1.7.2.min.js"></script> 
<script src="js/lightbox.js"></script> 

Include the Lightbox CSS file. 

<link href="css/lightbox.css" rel="stylesheet" /> 

Then use image from external url in this way 

<a href="http://www.hyperlinkcode.com" rel="lightbox" ><img src="/images/sample-image.gif" border="0"></a> 

The orignal url for this was 

http://hyperlinkcode.com/images/sample-image.gif