8
我想捕获闪亮的应用程序中iframe内链接的点击。我想知道哪个链接被点击。在闪亮的应用程序中捕获点击iframe中的内容
外面有光泽,这工作正常。我为相关问题添加了完全可重复的示例: https://stackoverflow.com/a/46093537/3502164 (它必须在(本地)服务器上运行,例如xaamp
)。
我尝试:
1)该应用程序将保存在Path/To/App
。
2)在www
文件夹中存储应该在iframe中显示的html文件。
fileWithLink.html
<html>
<body>
<a href="https://stackoverflow.com/">SOreadytohelp</a>
</body>
</html>
3)应用必须与runApp("Path/To/App", launch.browser = TRUE)
启动(这样一个本地服务器启动)。
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
htmlOutput("filecontainer")
)
server <- function(input, output, session){
session$onFlushed(once = T, function(){
runjs("
console.log('I arrive here')
$('#filecontainer').load(function(){
console.log('But not here')
var iframe = $('#filecontainer').contents();
iframe.find('#a').click(function(){
alert('I want to arrive here');
});
});
")
})
output$filecontainer <- renderUI({
tags$iframe(src = "fileWithLink.html", height = 600, width = 1200)
})
}
shinyApp(ui, server)