Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/366.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/73.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
Javascript 检测嵌入式网页上的点击_Javascript_Html_Css_Ruby On Rails - Fatal编程技术网

Javascript 检测嵌入式网页上的点击

Javascript 检测嵌入式网页上的点击,javascript,html,css,ruby-on-rails,Javascript,Html,Css,Ruby On Rails,假设我在一个网站上有一个嵌入式网页(例如:www.en.wikipedia.org/wiki/Pulsar)。用户单击文章内的超链接(例如: ) 我希望有一个框架,当用户单击原始文章(“脉冲星”)中的条目时,显示文章的名称(在本例中为“太阳系外行星”) 我如何知道用户单击了什么 编辑:在看过很多例子后,我试着这样做,但效果不太好 <iframe width="940" height="550" src="http://en.wikipedia.org/wiki/Special:Random

假设我在一个网站上有一个嵌入式网页(例如:www.en.wikipedia.org/wiki/Pulsar)。用户单击文章内的超链接(例如: )

我希望有一个框架,当用户单击原始文章(“脉冲星”)中的条目时,显示文章的名称(在本例中为“太阳系外行星”)

我如何知道用户单击了什么

编辑:在看过很多例子后,我试着这样做,但效果不太好

<iframe width="940" height="550" src="http://en.wikipedia.org/wiki/Special:Random">    </iframe>


<script>
(document.getElementsByTagName('iframe').contentWindow.document).keydown = function() {
alert("Hello World")
})
</script>

(document.getElementsByTagName('iframe').contentWindow.document).keydown=function(){
警报(“你好,世界”)
})

contentWindow
iframe
window
对象。这里需要
iframe
文档

$(document.getElementById('iframe_id').contentWindow.document).keydown(function() {
    // my func
});


这不起作用,因为您使用的是返回数组的
getElementsByTagName
。改为使用
getElementById
getElementsByTagName('iframe')[0]

您可以像这样在iframe中附加事件侦听器。这在Javascript中,对吗?我已经在网页中嵌入了HTML目标代码。是的,这是javascript。您需要javascript来检测点击。对吗?HTML永远无法做到这一点。我不明白你在评论中问了什么。我期待着当用户点击嵌入网站内的某个东西时会出现警报,但我不明白。
  $(document.getElementById('iframe_id').contentWindow.document).click(function() {
        // my func
    });