首页 > 解决方案 > 有没有办法检测在 iframe 中单击的链接,而不是打开新选项卡,而是将 iframe src 更改为该链接?

问题描述

这是代码和链接。提前致谢。 https://codepen.io/Vanceagher/pen/ExYpYxq?editors=1100

<html>
<head>
<stlyle>
html, body {
  padding: 0;
  margin: 0;
  background-color: #333;
}

iframe {
  width: 100vw;
  height: 80vh;
  padding-top: 5vh;
}

.stuff {
  height: 5vh;
}

#URL {
  border-radius: 10px;
  width: 25vw;
}

.frmSubmit {
  border-radius: 10px;
}

#btn {
  border-radius: 10p
}
</style>
  <title> iFrame </title>
  <script language="javascript"> 
   function LoadPage(){ 
     var objFrame=document.getElementById("myIframe"); 
     objFrame.src=document.getElementById("URL").value;
    }
  </script>
</head>
<body>
  <div ID="stuff">
<div style="Clear:both;"> 
 <input type="text" value="https://www.bing.com" class="frmUrlVal" ID="URL">
 <input type="submit" class="frmSubmit" value="Go" onclick="LoadPage()">
 <input type="button" VALUE="&lt; &lt; &nbsp; Back &nbsp;"  onClick="myIframe.history.back()"> 
 <input type="button" VALUE="Forward &nbsp; &gt; &gt;"  onClick="myIframe.history.forward()"> 
</div>
  </div>
<iframe sandbox="allow-same-origin allow-scripts allow-pointer-lock allow-forms" align="center" src="https://www.bing.com" frameborder="no" scrolling="yes" name="myIframe" id="myIframe"></iframe>
</body>
</html>

谢谢!废话

标签: google-chromeiframebrowsercodepen

解决方案


推荐阅读