使用 .document.getElementById 显示我网站上其他页面的元素

发布于 2024-11-07 08:55:24 字数 556 浏览 2 评论 0原文

我已经搜索这个主题好几天了。并且找不到可行或结论性的答案。

我想要做的就是在我网站(不是我的博客)首页的 div 容器中简单地显示最新博客条目(来自我自己网站上的博客页面)的(样式化)摘要。理想情况下,该镜像博客条目的所有活动链接都会指向我的博客页面的相应部分。然而,这不是必须的,只要整个条目可以链接到博客页面即可。

博客摘要页面上的每个博客条目摘要都有一个唯一的 ID,按数字排序(例如 unique-ID-51(最新)unique-ID-50(之前的 ID) ) ETC。) 我正在考虑使用 document.getElementById JS 命令来执行此操作。

我必须将 JS 函数指向一个相对位置 (../blog_folder/blog_summary.html),可能使用 .window.location.assign 命令,而不是抓取最新元素的(样式化)内容并将其显示在我的首页上。

但我不知道该代码在现实中会是什么样子。你能指出我正确的方向吗?

谢谢 !!!!!!!

M。

I have been searching about this subject now for quite a few days. And could not find a working or conclusive answer.

What I want to do, is to simply display the (styled) summary of the latest blog entry (from the blog page on my own site) in a div container on the front page of my site (which is not my blog). All active links of that mirrored blog entry ideally lead to the appropriate section of my blog page. That is however not a must, as long as the entire entry can link to the blog page.

Each blog entry summary on the blog summary page has a unique ID, sorted by numbers (e.g. unique-ID-51 (latest) unique-ID-50 (the one before) etc.)
I was thinking of doing so with the document.getElementById JS command.

I would have to point the JS function to a relative location (../blog_folder/blog_summary.html) with maybe the .window.location.assign
command, than grab the (styled) contents of the latest element and display that on my front page.

But I have no idea how that code would look in reality. Can you point me in the right direction?

Thank you !!!!!!!

M.

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

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

发布评论

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

评论(2

老街孤人 2024-11-14 08:55:24

您可以将 jQuery 添加到页面并使用简单的构造:

$('.result-container').load('path/to/your/file.html #id_of_element_to_fetch');

示例代码块:

...
<body>
  <div class="result-container">There will be your content from some file.</div>
  <p>
    <a class="result-loader" href="#"></a>
    <script type="text/javascript">
        $(".result-loader").click(function() {
             //Replace path/to/your/file.html and #id_of_element_to_fetch with appropriate values
             $('.result-container').load('path/to/your/file.html #id_of_element_to_fetch');
             return false;
        });
    </script>
  </p>
</body>
...

以及 标记内某处的字符串:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>

具有自动启动功能的示例代码块:

...
<body>
  <div class="result-container">There will be your content from some file.</div>
  <p>
    <a class="result-loader" href="#"></a>
    <script type="text/javascript">
        $(document).ready(function() { //Launches the code below right after the initialization event
             //Replace path/to/your/file.html and #id_of_element_to_fetch with appropriate values
             $('.result-container').load('path/to/your/file.html #id_of_element_to_fetch');
             return false;
        });
    </script>
  </p>
</body>
...

You could add jQuery to your page and use a simple construction:

$('.result-container').load('path/to/your/file.html #id_of_element_to_fetch');

An example chunk of code:

...
<body>
  <div class="result-container">There will be your content from some file.</div>
  <p>
    <a class="result-loader" href="#"></a>
    <script type="text/javascript">
        $(".result-loader").click(function() {
             //Replace path/to/your/file.html and #id_of_element_to_fetch with appropriate values
             $('.result-container').load('path/to/your/file.html #id_of_element_to_fetch');
             return false;
        });
    </script>
  </p>
</body>
...

And that string somewhere inside the <head> tag:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>

An example chunk of code with an autostart feature:

...
<body>
  <div class="result-container">There will be your content from some file.</div>
  <p>
    <a class="result-loader" href="#"></a>
    <script type="text/javascript">
        $(document).ready(function() { //Launches the code below right after the initialization event
             //Replace path/to/your/file.html and #id_of_element_to_fetch with appropriate values
             $('.result-container').load('path/to/your/file.html #id_of_element_to_fetch');
             return false;
        });
    </script>
  </p>
</body>
...
茶色山野 2024-11-14 08:55:24

我假设您使用的是隐藏的 iframe?

例如,这将改变样式的高度..样式中还有其他内容

    this.container.getElementsByTagName("YOUuniqueID")[0].style.(STYLE)

但是您必须在 iframe 中放置一个唯一的 ID

尝试并使用 IE 或 Chrome 中的内置调试器来查找您想要的内容...

您可以看看这个,也许有更多的信息(它是跨域的),但可能有一些东西可以帮助你。您甚至可以考虑使用 jquery 来访问该数据。

另一个跨域 iframe 调整大小的问答

I assume you are using a hidden iframe?

This for example will thet the height of the style.. there are other things in the style

    this.container.getElementsByTagName("YOUuniqueID")[0].style.(STYLE)

But you have to put an unique ID in the iframe

Try and use the built in debuggers in IE or Chrome to find what you want...

You can take a look at this for maybe some more info(its for cross domain) but there could be something taht helps you. You might even consider using jquery to access that data.

Yet Another cross-domain iframe resize Q&A

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