来自另一页的getElementById [英] getElementById from another page

查看:67
本文介绍了来自另一页的getElementById的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从一个网页URL到另一个网页获取一个div,并使用getElementById以纯文本显示,而不使用AJAX或jQuery,因为我要在FitNesse中实现它.有没有办法传递URL?

I am trying to get one div from one webpage URL to another webpage and display in plain text using getElementById without using AJAX or jQuery because I'm going to implement it in FitNesse. Is there a way to pass the URL?

推荐答案

您可以将URL加载到隐藏的iframe中.

You could load the URL in a hidden iframe.

然后使用此处概述的iframe.contentWindow.document.getElementById($ id):

Then use iframe.contentWindow.document.getElementById($id) as outlined here: How to pick element inside iframe using document.getElementById

类似的东西:

<iframe src="urlWithinYourDomain.html" style="display:none"></iframe>

后跟类似的功能:

var divElement = document.getElementById('iframeId').contentWindow.document.getElementById('elementIdOnSourcePage');
document.getElementById('targetParentId').appendChild(divElement);

恐怕我目前无法测试,因此可能存在语法错误,但我认为它传达了这一想法.这是一个肮脏的方法,但是鉴于您的限制,这是我看到的执行您所要求的最佳方法.

I'm afraid I can't test this at the moment, so there may be syntax errors, but I think it conveys the idea. It's a bit of a dirty approach, but given your constraints it's the best way I can see to do what you're asking.

这篇关于来自另一页的getElementById的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆