【问题标题】:Redirect an iFrame when it is clicked by the user用户单击时重定向 iFrame
【发布时间】:2020-10-05 06:01:41
【问题描述】:

当用户单击 iFrame 时,如何将 iFrame 重定向到另一个 html 网页?

iFrame实际上是一个html页面。当我点击iFrame时,我希望它重定向到另一个html页面。

我的代码:

         h1 {
            text-align: center;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
         }
         h2{
            text-align: center;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            
         }
         body {   
            background-color: #feb236;
         }
         iframe {
            border: 2px solid black;
         }
         body{
             height: 175vh;
         }
         div{
            border-width: 0 2px;
            border-style: solid;
            position: fixed;
            top: 0;
            bottom: 0;
            right: 400px;
            left: 400px;
            z-index: -1;
         }
<!DOCTYPE html>
<html>

   <head>
      <title>Plagiarism</title>
      <h1><u>PLAGIARISM</u></h1>
      <div></div>
   </head>
   
   <body>
      <h2 style=>What is Plagiarism?</h2>
      <p align="center"><iframe width="400" height="250"></iframe></p>
      <h2>What is Plagiarism in Computer Science?</h2>
      <p align="center"><iframe width="400" height="250"></iframe></p>
      <h2>Famous Cases of Plagiarism</h2>
      <p align="center"><iframe width="400" height="250"></iframe></p>
      <h2>Punishment for Plagiarism in US</h2>
      <p align="center"><iframe width="400" height="250"></iframe></p>
   </body>
   
   
</html>

【问题讨论】:

    标签: javascript html css iframe frame


    【解决方案1】:
    <html>
    <head>
    <title>Test IFrame SRC by Javascript </title>
    
    <script>
    function RedirectPage()
    {
     document.getElementById("frame1").src = "http://WWW.microsoft.com";
    }
    </script>
    </head>
    <body>
    <table>
    <tr>
    <td>
         <iframe name="frame1" src="http://www.w3schools.com" width="500px" height="500px"></iframe>
    </td>
    </tr>
    <tr><td>
    <input type="button" value="Change IFrame sRC Location" name="btnRedirect" runat="server" onclick="RedirectPage()"/>
    </td></tr>
    </table>
    
    </body>
    </html>
    

    这段代码或许能帮到你。

    【讨论】:

      猜你喜欢
      • 2011-03-11
      • 1970-01-01
      • 2019-06-01
      • 1970-01-01
      • 2012-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多