javascript - React如何在iframe中输出名称

标签 javascript reactjs iframe react-redux

我在 React 中得到了电影的名称,一切看起来都很棒

{movie.name}/{movie.enname} ({years})

h1 (Knives Out/《利刃出鞘》(2019))/h1

。但 我无法在 https://example.com/movie/ 的 iframe 窗口中显示此名称{movie.name} 这是 iframe:

<iframe src="https://example.com/movie/?imdb={movie.name}&notitle=1&cover=11" alt="{movie.imdb_id}" allowfullscreen width="50%" height="350" frameborder="0" scrolling="no"></iframe>

因此它仍然是 {movie.name} 和 {movie.imdb_id},而不是收到的名称 Knives Out。 如何解决?

最佳答案

变量名称被视为 iframe src 中的字符串

使用template literals

示例

<iframe src={`https://example.com/movie/?imdb=${movie.name}&notitle=1&cover=11`} alt={movie.imdb_id} allowfullscreen width="50%" height="350" frameborder="0" scrolling="no"></iframe>

<iframe src={"https://example.com/movie/?imdb="+movie.name+"&notitle=1&cover=11" } alt={movie.imdb_id} allowfullscreen width="50%" height="350" frameborder="0" scrolling="no"></iframe>

关于javascript - React如何在iframe中输出名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59404571/

相关文章:

javascript - React Js,this.context 在构造函数方法中未定义

javascript - react native : Accessing values in returned object: undefined

javascript - Expo React Native 仅加载自定义字体一次

javascript - 如果 anchor 内部有 iframe,则无法单击 anchor

javascript - Reveal JS 去除特定幻灯片的固定纵横比

javascript - 代码与 ramda.js 有什么区别?

javascript - 期望点击按钮打开文件浏览器

javascript - location.state 因 gatsby 构建而失败

android - 重复的包react-native

php - Paypal 托管 iFrame 错误 : "Error Processing Payment.This transaction can' t be processed. 请使用另一张卡支付。”