我希望在闪亮的应用中捕获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>
Run Code Online (Sandbox Code Playgroud)
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)
}) …Run Code Online (Sandbox Code Playgroud)