Javascript 如何在iframe中动态加载页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5142825/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 15:50:10  来源:igfitidea点击:

How to load page dynamically in iframe

javascriptiframe

提问by Developer404

I just want to load an html page in iframe on clicking a link or button in the same page. I used javascript to load the page dynamically. But, I couldn't do that. Please anyone guide me to do that. My code is as follows:

我只想在单击同一页面中的链接或按钮时在 iframe 中加载一个 html 页面。我使用 javascript 动态加载页面。但是,我做不到。请任何人指导我这样做。我的代码如下:

document.getElementById("iframeelem").src="newhtml.jsp";

回答by Jakub Konecki

Your code is correct. Here is a tutorial, just in case: http://www.dyn-web.com/tutorials/iframes/

你的代码是正确的。这是一个教程,以防万一:http: //www.dyn-web.com/tutorials/iframes/

What is the error?

错误是什么?

Verify the id of your frame and url are correct (type in the url in a browser window and make sure you get your page).

验证您的框架的 id 和 url 是否正确(在浏览器窗口中输入 url 并确保您获得了您的页面)。

回答by Wyken Seagrave

Put this on the embedded page

把这个放在嵌入的页面上

<p>
<input type='button' name='Next' value='Next Page'
onclick='window.location.replace("http://timecrystal.co.uk/");' />
</p>