且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Twitter引导模式外部URL不起作用

更新时间:2023-11-18 11:55:58

这不起作用,因为您违反了相同的原始政策限制,阻止您发送跨域AJAX请求,这是引导程序在此处使用的内容.因此,一种可能性是将外部内容加载到<iframe>:

This doesn't work because you are violating the same origin policy restriction that prevents you from sending cross domain AJAX requests which is what bootstrap is using here. So one possibility is to load the external content into an <iframe>:

$('a.btn').on('click', function(e) {
    e.preventDefault();
    var url = $(this).attr('href');
    $('.modal-body').html('<iframe width="100%" height="100%" frameborder="0" scrolling="no" allowtransparency="true" src="' + url + '"></iframe>');
});​

请注意,某些网站(例如google,***,facebook等)无法加载到iframe中.他们将X-Frame-Options响应HTTP标头设置为SAMEORIGIN,还检查是否将它们加载到iframe内部.

Be warned though that some sites (such as google, ***, facebook, ...) cannot be loaded into an iframe. They are setting the X-Frame-Options response HTTP header to SAMEORIGIN and also check if they are loaded inside an iframe.

您可以在此小提琴中看到它的作用: http://jsfiddle.net/f2Fcd/

You can see it in action in this fiddle: http://jsfiddle.net/f2Fcd/