简体   繁体   English

如何重定向或链接到另一个页面的DIV元素内的URL?

[英]How to Redirect or Link to a URL Inside Another Page's DIV Element?

I have a page setup on Sharepoint with four different links with descriptions under them that are ever changing. 我在Sharepoint上有一个页面设置,具有四个不同的链接,这些链接下的描述不断变化。 Right now, I have the title of each link and the description of each link pulling from another page (an .aspx article page) that my co-workers can update easily. 现在,我有了每个链接的标题以及从另一个页面(一个.aspx文章页面)提取的每个链接的描述,我的同事们可以轻松地对其进行更新。 So when they update their article, jquery updates the title and description of all four of the links. 因此,当他们更新文章时,jquery会更新所有四个链接的标题和描述。 The problem I have is getting the actual url destination (href) to update from a div on my co-worker's article page. 我的问题是要获取实际的URL目标(href),以从同事的文章页面上的div更新。 All the code I can find for changing an href use .attr to accomplish something similar but in all examples I've found, that requires putting in the new url right in the code. 我可以找到的用于更改href的所有代码都使用.attr来完成类似的操作,但在我发现的所有示例中,都需要在代码中放入新的url。 This URL will change each time they change their article. 每当他们更改文章时,此URL都会更改。 Any ideas? 有任何想法吗? (I am not a coder but a Graphic Designer with minor HTML and Javascript knowledge) (我不是编码员,而是具有一点HTML和Javascript知识的平面设计师)

First the Script: 首先是脚本:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("#CI1").load("http://jfghome/CorpInitiatives/Pages/Corporate%20Initiatives/CI1.aspx #newstitle");
$("#CI1b").load("http://jfghome/CorpInitiatives/Pages/Corporate%20Initiatives/CI1.aspx #newsbody");
$("#CI2").load("http://jfghome/CorpInitiatives/Pages/Corporate%20Initiatives/CI2.aspx #newstitle");
$("#CI2b").load("http://jfghome/CorpInitiatives/Pages/Corporate%20Initiatives/CI2.aspx #newsbody");
$("#CI3").load("http://jfghome/CorpInitiatives/Pages/Corporate%20Initiatives/CI3.aspx #newstitle");
$("#CI3b").load("http://jfghome/CorpInitiatives/Pages/Corporate%20Initiatives/CI3.aspx #newsbody"); 
$("#CI4").load("http://jfghome/CorpInitiatives/Pages/Corporate%20Initiatives/CI4.aspx #newstitle");
$("#CI4b").load("http://jfghome/CorpInitiatives/Pages/Corporate%20Initiatives/CI4.aspx #newsbody"); 
$("#pCI1").attr('src',"http://jfghome/CorpInitiatives/PublishingImages/Image1.png");
$("#pCI2").attr('src',"http://jfghome/CorpInitiatives/PublishingImages/Image2.png");
$("#pCI3").attr('src',"http://jfghome/CorpInitiatives/PublishingImages/Image3.png");
$("#pCI4").attr('src',"http://jfghome/CorpInitiatives/PublishingImages/Image4.png");
});
</script>    

Now the HTML (These are no longer APDivs btw, I have since changed their CSS properties): 现在是HTML(顺便说一句,这些不再是APDivs,我更改了它们的CSS属性):

<div id="Col2">
<div id="apDiv5">
<div id="apDiv8"><a href="/CorpInitiatives/MOR/SitePages/Home.aspx"><img id="pCI1" src="/CorpInitiatives/SiteAssets/SitePages/Home%20Testing/ajax-loader100x70.gif" width="100" height="70" alt="1" /></a></div>
<div id="apDiv10"><strong><a href="/CorpInitiatives/MOR/SitePages/Home.aspx" style="color:#324c71; font-size:16px; font-family: Cambria, Hoefler Text, Liberation Serif, Times, Times New Roman, serif; font-size:18px"><div id="CI1">Loading...</div></a></strong>
<div id="CI1b">...</div></div>
</div>
<div id="apDiv3">
<div id="apDiv9"><a href="/CorpInitiatives/SitePages/JFGHomeInfo.aspx"><img id="pCI2" src="/CorpInitiatives/SiteAssets/SitePages/Home%20Testing/ajax-loader100x70.gif" width="100" height="70" alt="2" /></a></div>
<div id="apDiv11"><strong><a href="/CorpInitiatives/SitePages/JFGHomeInfo.aspx" style="color:#324c71; font-size:16px; font-family: Cambria, Hoefler Text, Liberation Serif, Times, Times New Roman, serif; font-size:18px"><div id="CI2">Loading...</div></a></strong><div id="CI2b">
...</div></div>
</div>
<div id="apDiv2">
<div id="apDiv12"><strong><a href="/resources/TalkingPoints/SitePages/Scorecard.aspx" style="color:#324c71; font-size:16px; font-family: Cambria, Hoefler Text, Liberation Serif, Times, Times New Roman, serif; font-size:18px"><div id="CI3">Loading...</div></a></strong>
<div id="CI3b">...</div></div>
<div id="apDiv13"><a href="/resources/TalkingPoints/SitePages/Scorecard.aspx"><img id="pCI3" src="/CorpInitiatives/SiteAssets/SitePages/Home%20Testing/ajax-loader100x70.gif" width="100" height="70" alt="3" /></a></div>
</div>
<div id="apDiv6">
<div id="apDiv14"><strong><a href="/CorpInitiatives/Pages/townhallrecap2013.aspx" style="color:#324c71; font-size:16px; font-family: Cambria, Hoefler Text, Liberation Serif, Times, Times New Roman, serif; font-size:18px"><div id="CI4">Loading...</div></a></strong>
<div id="CI4b">...</div></div>
<div id="apDiv15"><a href="/CorpInitiatives/Pages/townhallrecap2013.aspx"><img id="pCI4" src="/CorpInitiatives/SiteAssets/SitePages/Home%20Testing/ajax-loader100x70.gif" width="100" height="70" alt="4" /></a></div>
</div>
</div>

So this does the trick for everything except grabbing the url from a div on my co-workers article and placing it in the href on my page. 因此,除了从我的同事文章中的div中获取URL并将其放置在我页面的href中之外,这一切都可行。 Please help! 请帮忙! All suggestions are greatly appreciated. 所有建议,不胜感激。

I think i dont understand al all your question, i think you're asking how to redirect or link to a div inside another page? 我想我不太了解您的所有问题,我想您是在问如何重定向或链接到另一个页面内的div?

If is, then put your url finishing with this #{div_id}, no spaces between the end of the link and the div id, hope this helps 如果是,请在URL末尾添加此#{div_id},在链接末尾和div id之间没有空格,希望这对您有所帮助

If I'm understanding you correctly, there's another page that contains a link, and you want to load the content from that link into your page. 如果我对您的理解正确,那么会有另一个页面包含链接,并且您希望将链接中的内容加载到页面中。

Would something like this work? 这样的事情行吗?

mainPage.html

<script>
$(document).ready(function() {
    $('#mainDiv').load('pageToLoadLinkFrom.html', function() {
        $('#mainDiv').load($(this).find('#specialLink a').attr('href'))
    })
})
</script>

...

<body>
  <div id="mainDiv" />
</body>

And then... 接着...

pageToLoadLinkFrom.html

<body>
  <div id='specialLink'><a href="someOtherPage.html">Some Other Page</a></div>
</body>

The href in link in other page contains a relative link to that page. 其他页面中的href in链接包含指向该页面的相对链接。 from your page, if you want use those links, you need to make sure your page is under the same dir with target page in the same server or get window.location of target page. 从页面中,如果要使用这些链接,则需要确保页面与目标服务器在同一服务器中的目录位于同一目录下,或者获取目标页面的window.location。 Then you could construct an absolute url so you can use it. 然后,您可以构造一个绝对URL,以便可以使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM