1

我一直在寻找这个主题已经好几天了。并且找不到有效或确凿的答案。

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

博客摘要页面上的每个博客条目摘要都有一个唯一的 ID,按数字排序(例如unique-ID-51(最新的)unique-ID-50(之前的)等。我正在考虑使用document.getElementByIdJS 命令这样做。

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

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

谢谢 !!!!!!!

M。

4

2 回答 2

1

您可以将 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>
...

<head>以及标签内某处的那个字符串:

<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>
...
于 2011-05-14T10:16:46.333 回答
0

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

例如,这将是样式的高度。样式中还有其他内容

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

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

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

您可以查看此内容以获取更多信息(用于跨域),但可能对您有所帮助。您甚至可以考虑使用 jquery 来访问该数据。

Yet another cross-domain iframe resize Q&A

于 2011-05-14T10:13:52.873 回答