我需要 iframe 的 document.write 代码

发布于 2024-09-07 18:00:03 字数 199 浏览 0 评论 0原文

我想要 document.write 代码加载页面(作为 iframe)

示例 - 我需要 document.write 函数来获取 http://google .com

我不想要 html 函数,而是想要 document.write

I want the document.write code to load a page(as iframe)

example - i need document.write function to get http://google.com

I dont want html function but as document.write

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

也只是曾经 2024-09-14 18:00:03

我不确定您是否知道 document.write 方法的作用...

document.write 方法用于将 HTML 代码写入当前文档。如果在加载时完成,代码将成为当前加载文档的一部分。如果在页面加载后完成,它将替换当前页面。

您可以使用该方法将代码写入窗口或框架,但不能使用它来更改窗口的位置。即使您从 google.com 获取 HTML 代码并将其写入窗口,该位置也不会是 google.com,因此该代码很可能无法正常工作。

如果您想更改窗口的位置,只需使用 location.href 属性:

window.location.href = 'http://google.com';

I'm not sure that you know what the document.write method does...

The document.write method is used to write HTML code into the current document. If it's done at load time, the code becomes part of the document currently loading. If it's done after the page has loaded, it will replace the current page.

You can use the method to write code to a window or a frame, but you can't use it to change the location of the window. Even if you get the HTML code from google.com and write it to a window, the location will not be google.com so the code will most likely not work properly.

If you want to change the location of a window, you just use the location.href property:

window.location.href = 'http://google.com';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文