Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在jQueryUI对话框中打开URL_Jquery_Html_Jquery Ui_Jquery Ui Dialog - Fatal编程技术网

如何在jQueryUI对话框中打开URL

如何在jQueryUI对话框中打开URL,jquery,html,jquery-ui,jquery-ui-dialog,Jquery,Html,Jquery Ui,Jquery Ui Dialog,我一直在寻找一个简单的解决方案,已经有一段时间了。我希望在jQueryUI对话框窗口中显示一个页面(例如)。计划是在以后动态添加URL,这样我的站点的所有链接都将显示在所述窗口中 我尝试了以下方法,但单击链接时对话框窗口为空 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> &l

我一直在寻找一个简单的解决方案,已经有一段时间了。我希望在jQueryUI对话框窗口中显示一个页面(例如)。计划是在以后动态添加URL,这样我的站点的所有链接都将显示在所述窗口中

我尝试了以下方法,但单击链接时对话框窗口为空

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Test</title>


<meta charset="utf-8" />
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
  <script>
$(document).ready(function() {
    $('#openwindow').each(function() {
        var $link = $(this);
        var $dialog = $('<div></div>')
            .load($link.attr('href'))
            .dialog({
                autoOpen: false,
                title: $link.attr('title'),
                width: 500,
                height: 300
            });

        $link.click(function() {
            $dialog.dialog('open');

            return false;
        });
    });
});
  </script>

</head>
<body>
<a id="openwindow" href="http://www.google.com">Click me to test.</a>
</body>
</html>

试验
$(文档).ready(函数(){
$('#openwindow')。每个(函数(){
var$link=$(此);
变量$dialog=$('')
.load($link.attr('href'))
.对话({
自动打开:错误,
标题:$link.attr('title'),
宽度:500,
身高:300
});
$link.click(函数(){
$dialog.dialog('open');
返回false;
});
});
});
我找到了一些例子,但没有一个真正起作用。我非常感谢你的帮助

提前感谢。

您可以使用iframe:

 $("#iframeId").attr("src", $(this).attr("href"));
 $('#dialogId').dialog('open');

您不需要像建议的那样使用
iframe
,但您应该阅读对话框上的文档

相反,您需要在
.open
属性上加载内容--

此外,您似乎使用了
。每个
都带有
id
id
在页面中应该是唯一的。改用
class

可能会有帮助。。在这里,我所做的是将鼠标悬停在一个链接上,url将在一个对话框中打开。。 如果动态创建了多个相同的标记,则应该使用
class
而不是
id
。哦,也就是说,它只适用于单个
id

$('.openwindow').click(function(){
var $this=$(this);
         $.ajax({
                url: $this.attr('href');//You got the link here
                success: function(data) {
                    //show the dialog here..
                    //"data" contains the html returned by the url
                },
                error: function(jqXHR){
                    //Do something here
                }
              });
        });
你可以试试这个

$(function(){
    $('a').on('click', function(e){
        e.preventDefault();
        $('<div/>', {'class':'myDlgClass', 'id':'link-'+($(this).index()+1)})
        .load($(this).attr('href')).appendTo('body').dialog();
    });
});
$(函数(){
$('a')。在('click',函数(e)上{
e、 预防默认值();
$(“”,{'class':'myDlgClass','id':'link-'+($(this.index()+1)})
.load($(this.attr('href')).appendTo('body').dialog();
});
});
上面的代码将在单击页面上的任何链接时创建一个新的
对话框
,还将为每个对话框添加一个类名
myDlgClass
和一个唯一的id,如
link-1
link-2
等等,但请记住,由于同源策略,只加载页面链接而不会加载外部链接

更新:
要使用外部站点链接,您可以使用
iframe
,这里是。

基本上您需要ajax调用,是吗?如果URL位于另一个域中,由于跨域ajax限制,您不能使用
.load()
$('.openwindow').click(function(){
var $this=$(this);
         $.ajax({
                url: $this.attr('href');//You got the link here
                success: function(data) {
                    //show the dialog here..
                    //"data" contains the html returned by the url
                },
                error: function(jqXHR){
                    //Do something here
                }
              });
        });
$(function(){
    $('a').on('click', function(e){
        e.preventDefault();
        $('<div/>', {'class':'myDlgClass', 'id':'link-'+($(this).index()+1)})
        .load($(this).attr('href')).appendTo('body').dialog();
    });
});