光沢のあるアプリで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)