在图像上单击重定向到其他页面并播放视频

本文关键字:播放 视频 其他 图像 单击 重定向 | 更新日期: 2023-09-27 17:56:11

我有两个页面食谱.aspx和食谱视频.aspx,在食谱页面上的图像将显示在每个图像点击相关视频应该在食谱视频.aspx上打开。

我试过这个,但它只重定向到其他页面

<asp:ImageButton ID="ImageButton1" ImageUrl="~/images/food-trending-meal-pops-L-qw162R.jpeg" runat="server" Height="94px" Width="141px" OnClick="ImageButton1_Click" />
 protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("~/RecipeVideo.aspx");
        }

请任何人给出如何做到这一点的想法。

在图像上单击重定向到其他页面并播放视频

一个可能的解决方案是——声明一个像这样的全局 JavaScript 变量

var videoSource= '';

它应该在所有函数之外的外部js文件中,最重要的是以下所有函数。然后让你的按钮像

<input type ="submit" id = "image-button" onclick ="ShowVideo('pass the src value of the corresponding video as the parameter')"/>

然后将显示视频方法添加为

function ShowVideo(source){
    videoSource = source;
    window.location.assign('url of second page you want to load');
}

然后在第二页上,您可以这样做

<iframe style = "Display: None" id = "video" width="854" height="480" src="" frameborder="0" allowfullscreen></iframe>
<script>
window.onload = SetVideo();
</script>

在外部 js 文件中添加方法

function SetVideo(){
    document.getElementById('video').src = videoSource;
}