【问题标题】:mootools moopopup url option not working?mootools moopopup url 选项不起作用?
【发布时间】:2013-08-08 20:20:06
【问题描述】:

我是 mootools 的新手,我正在开发 moopopup 的演示示例,但对我来说,加载远程的选项 url 不会弹出。

<link href="moopopup.css" type="text/css" rel="stylesheet" />
    <script type="text/javascript" src="mootools-core-yc.js"></script>
<script type="text/javascript" src="mootools-more-yc.js"></script>
<script src="moopopup-yc.js" type="text/javascript"></script>

<script type="text/javascript">
    function runExample3() { 
        var mypopup3 = new moopopup({
            title: 'My home page',
            resizable: false,
            width: 800,
            max_body_height: 600,
            url: 'http://www.google.co.in/'
        });
        mypopup3.display();     
    }
</script>
</head>

<body onLoad="prettyPrint()">
<span class="button link" onclick="runExample3();">run javascript</span>
</body>

这是网址:

http://sasi.pro/searchsn/new/

【问题讨论】:

  • 你搞定了吗?

标签: url popup mootools mootools-events mootools-fx


【解决方案1】:

由于跨域安全性,您不能直接做您想做的事。您不能将其他网站导入到您自己的 html 中。您可以发出 ajax 请求,但不能通过 ajax 导入 http://www.google.co.in/

我不确定您将如何使用 moopopup,但我看到的唯一选择是使用 moopopup 的 htmlnode 选项并将 iFrame 加载到其中。在这种情况下,它会起作用,你只剩下一点 CSS 工作了。不过,有些网站不允许在 iFrame 中显示自己,Google 就是其中之一。

DEMO HERE

我还对您的代码做了一些小改动,请注意,在您的网站/链接上,您在页面加载时调用的函数 prettyPrint() 不存在(可能是您拥有的其他代码的一部分)...

无论如何我在演示中的代码:

HTML

<span class="button link">run javascript</span>
<div id="newiframe">
    <iframe src="http://www.yr.no" id="newiframe" />
</div>

CSS

#newiframe {
    display:none;
    width:770px;
    height:300px;
    overflow:auto;
}
.moopopup-body #newiframe {
    display:block;
}

脚本

var myIframe = document.id('newiframe');
function runExample3() {
    var mypopup3 = new moopopup({
        title: 'My home page',
        resizable: false,
        width: 800,
        max_body_height: 600,
        html_node: myIframe
    });
    mypopup3.display();
}

document.getElement('.button.link').addEvent('click', runExample3);
//commented because it doesn't exist
// window.addEvent('domready', function() { prettyPrint();});

【讨论】:

  • 谢谢,第一次成功,第二次出现这个错误 TypeError: myIframe is null 我不知道为什么会这样..
  • 我也将 iframe url 更改为我的服务器..
  • @sasi,你想使用来自你域或其他域的 moopopup 中的内容吗?
  • 我想从其他域打开。
猜你喜欢
  • 2014-07-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多