简体   繁体   English

如何将一个 html 文件中的 href 标签链接到下一个 html 页面中的 iframe 标签

[英]how to link a href tag from one html file to iframe tag in next html page

what i am trying to do is,我想做的是,

  1. I have a html page lets say movieslist.html , it has a list of few movies (all are href links <a href="movie.html">我有一个 html 页面可以说movieslist.html ,它有几部电影的列表(都是 href 链接<a href="movie.html">
  2. Clicking on any movie will redirect me to movie.html .点击任何电影都会将我重定向到movie.html Here I am using iframe tag to display and play a video from my google drive.在这里,我使用iframe标签来显示和播放来自我的谷歌驱动器的视频。

Problem is that I am not getting how to link them both, for example if I give 2 iframe tag with drive link as src value both are getting display.问题是我不知道如何将它们链接起来,例如,如果我给出 2 个iframe标记和驱动链接作为src值,两者都得到显示。 I want only the movie which I have clicked to be displayed.我只想显示我单击的电影。 how to give this condition or any suggestions on this?如何给出这个条件或对此有任何建议?

Please help请帮忙

For this you need to propagate your movie link from movies.html to movie.html.为此,您需要将电影链接从 movies.html 传播到 movie.html。

movies.html电影.html

 <html>
    <body>
        <a href="movie.html?movieLink=https://drive.google.com/file/d/1oezcBrXr8b-ATkIGD1I9ZQakPP9VX_5W/preview">Movie 1</a>
        <a href="movie.html?movieLink=https://drive.google.com/file/d/1oezcBrXr8b-ATkIGD1I9ZQakPP9VX_5W/preview">Movie 2</a>
    </body>
</html>

movie.html电影.html

<html>
    <body>
    </body>
    <script>
        function bindUrlWithIFrame(){
            var movieLink = window.location.href.split("?movieLink=")[1];
            var iframeElement = document.createElement("iframe");
            iframeElement.src = movieLink;
            iframeElement.width = 1100;
            iframeElement.height = 500;
            document.body.appendChild(iframeElement);   
        }
        bindUrlWithIFrame();
    </script>
</html>

Firstly in movies.html send your movie link in href (hypertext reference) with parameter movieLink.首先在movies.html 中使用参数movieLink 在href(超文本参考)中发送您的电影链接。 Second in movie.html retrieve your movie link from URL bar and split by movieLink to get your actual movie link, then dynamically create your iframe element, pass the movie link to it as source, finally adding your iframe element to DOM will work. Second in movie.html retrieve your movie link from URL bar and split by movieLink to get your actual movie link, then dynamically create your iframe element, pass the movie link to it as source, finally adding your iframe element to DOM will work. Upvote for the same, Thanks.为相同点赞,谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM