如何在HTML中的特定Div中打开网站

How to open a website within a particular Div in HTML

本文关键字:Div 网站 HTML      更新时间:2023-09-26

我想让它打开一个网站在一个特定的<div>标签,就像在以下链接:响应。我做错了什么?

<html>
<head>
  <script>
   function mobile320()
    {
     window.location.assign("http://www.idevtechnolabs.com")
    }
  </script>
<style type="text/css">
 body{
  margin: 0px auto;
  padding: 0px;
  background: #06855a;
  text-align: center;
 }
.browser1{
  display: inline-block;
  position: relative;
  width: 320px !important;
  height: 480px !important;
  background: #efefef;
 }
</style>
</head>
 <body>
   <input type="button" value="Load new document" onclick="mobile360()" />
   <div class="browser1"> </div>
 </body>
</html>

这不是div,这是iframe:

<iframe src="http://www.google.com"></iframe>

在div中添加iframe元素,并导航到所需的网站,

或执行HTTP get请求并将所需div的内部HTML设置为u get的响应字符串。

把你的函数改成这样:

function mobile320() {
    document.querySelector(".browser1").setAttribute("src", "http://www.idevtechnolabs.com");
}

…把div改成这个…

<iframe class="browser1"></iframe>