Using link in the client Web part

Source: Internet
Author: User

<span style= "font-family:arial, Helvetica, Sans-serif; Background-color:rgb (255, 255, 255); " > Original address </span><a target=_blank href= "http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2012/ 12/10/working-with-links-in-a-client-web-part.aspx "style=" font-family:arial, Helvetica, Sans-serif; Background-color:rgb (255, 255, 255); " >working with links in a Client Web part</a><span style= "font-family:arial, Helvetica, Sans-serif; Background-color:rgb (255, 255, 255); " > This article by </span><a Target=_blank href= "Http://blog.csdn.net/spfarm" style= "font-family:arial, Helvetica, Sans-serif; Background-color:rgb (255, 255, 255); " >spfarmer</a><span style= "font-family:arial, Helvetica, Sans-serif; Background-color:rgb (255, 255, 255); " > Translation </span>

If you've read myarticle,so you're in the newSharePoint App ModelThe use of a client page part in a good start. In theApp partinside, all the things you do,are in aIFRAMEinside. Any time, when you are inApp Partcreated inLink, you must keep this in mind. It's a little complicated, but it's not as complicated as it might seem. Where do you start? Let's first look at the link toappWhat you need to do with the default page. In general, this page is calledDefault.aspx, he'sURLgenerally similar to:

Http://app-4715ba34d5bfe2.apptest.local/sites/developer/HelloWorldApp/Pages/Default.aspx

effectivelythisURLhas a prefix(APP),aId,one to store thisAppsof thesubdomain,at present I am in aDeveloperrun this on the siteapp, Next isApp Name, which is ultimatelyPagesfolder (and theVisual StudioThe name in the match.). That holds the client page part.aspxpage, which is usually also in this folder. In my case, yes. helloworldclientwebpart.aspx . That is, if I want to create a link in my client page widget to myappof the default pageLink, I should be able to do this:

< a href= "default.aspx" >Go to App default page</a>

this should be linked app the default page, but unfortunately, the following is the display result.


The link is no problem, but the page is designed to run across the browser, so it has no allowframing tags. To fix this it's easy to add a target= "_top"so that link will open in the parent frame instead of ifream. For example :

< a href= "default.aspx" target= "_top" >Go to App page 2</ a >

now Link It's easy to use.

Another common scenario you might encounter is linking to a related list. Suppose I have a list called testlist, whose relative path is lists/testlist. We can get to this, but we need to usea relative path and go up one folder first since the page executes out of  Thepages Library. Here's what the link would look like.

< a href= "... /lists/testlist " target=" _top ">Go to List</a>

Finally, sometimes you might want to get a page in the client Web widget App Web of the Link . You can use the same CSOM to achieve your goal. start by getting a reference to the app Web.

var Context;var web;context = new SP. Clientcontext.get_current (); web =context.get_web ();


then you need to load Context , run the query to get to the Web object.

Context.load (web); Context.executequeryasync (onurlrequestsucceeded,onqueryfailed);


in the Success in the method , you can read the URL. and so I got on the page Link reference, and then I can modify it, assign a href property.

function onurlrequestsucceeded () {

var appweburl = Web.get_url ();

$ ("#MyLink"). attr ("href", appweburl);

}

when using Link , you can now have multiple options. This is not very complicated, but it is worth writing down.

Published Dec, 10:00am by Coreyroth

Filed under: SharePoint, SharePoint, Apps

Using link in the client Web part

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.