无法访问<object>元素(Javascript \ jQuery)</object>的URL属性

时间:2013-03-22 03:10:48

标签: javascript jquery frame html-object

我遇到的问题是无法访问与<object> - html元素对应的对象中包含的数据,该元素用于以显示其他网站。用例场景是我想在我的页面中显示外部网站,我希望知道用户点击的链接(在此集成的外部网站中)

具体来说,我对 URL 或文档的名称感兴趣。当我试图获取这些数据时(我在使用firebug浏览对象时可以看到)我无法做到这一点。以某种方式限制访问或我做错了。

这正是我正在做的事情。

1)我定义了一个维基百科文章作为数据源的对象

<object id='wikiframe' data='http://en.wikipedia.org/wiki/thing' width='100%' height='700px'> Error: Embedded data could not be displayed. </object>

2)我为文档定义了一个click事件,以便知道用户何时点击

$(function() {
    document.onclick = myClickHandler;
    function myClickHandler() {
        // Please help to assign a string with the wikipedia article name or with the string of url of the link which was clicked to the variable articleName;
        var articleName;
        var wikiObject = $("#wikiframe");
        alert('The name of the currenttly opened wiki article is: ' + articleName);
    }
});

现在出现以下问题:

1)如果我在文章中点击,则点击事件不会触发。 2)我无法访问与此元素对应的对象中包含的数据。但是正如你在屏幕截图中看到的那样,我需要的信息。

在屏幕截图中,您会看到一条维基百科文章,该文章是通过点击首次显示的文章中的链接打开的。 Firebug显示我需要的信息(在这种情况下是文章“Noumenon”的URL

Link to image displaying the properties I want to access http://img856.imageshack.us/img856/3217/informationcontainedino.png

请告诉我需要添加的内容,以便为articleName分配一个包含所点击链接网址的字符串。

整个代码在这里:

<!doctype html>
<html lang="en">

<head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</head>

<body>
    If you click anywhere except the object click event fires. If you click on object it does not. I want the click event firing on clicking within wiki article and showing either a) the name of currently opened article OR b) the url of the clicked link
    <object id='wikiframe' data='http://en.wikipedia.org/wiki/thing' width='100%' height='700px'> Error: Embedded data could not be displayed. </object>
</body>

<script>
    $(function() {
        document.onclick = myClickHandler;
        function myClickHandler() {
            // Please help to assign a string with the wikipedia article name to the variable articleName;
            var articleName;
            var wikiObject = $("#wikiframe");
            alert('The name of the currenttly opened wiki article is: ' + articleName);
        }
    });
</script>

</html>

0 个答案:

没有答案
相关问题