Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'd like to have access to sharepoint's query string from inside of my app. Since the app is hosted in an iframe, I tried just using window.top.location.search, but that gives me an error since the URL is different for my iframe vs. the parent window.

Is there a way I can see the query string of the SP url inside of my app? If not, how can I pass dynamic data easily to my app through a link, like I could with a query string parameter?

share|improve this question
    
Did you get this resolved? I am wondering how to achieve the exact same thing. –  Graham May 30 '13 at 1:09
    
I ended up changing how the site was hosted to be a subdomain of the SP site, and did some document.domain manipulation to get around the error. Let me know if you need more information than that and I can post a full answer for you. –  Colin DeClue May 30 '13 at 14:01
    
How did this work with the app part? document.domain would be the app's URL. –  EHorodyski Jul 5 '13 at 13:47
    
Correct, but I knew that document.domain would be app.[domain] while the host was [domain]. Basically, it was a provider hosted app and I had control over the domain names. If it's an auto-hosted app, this method won't work, and I'm not sure what to do. –  Colin DeClue Jul 9 '13 at 16:37
    
did you find the resolution for this problem? –  user18939 Aug 14 '13 at 21:24

4 Answers 4

Script to get the current page URL/pass the query string from the **SharePoint hosted apps**

var currentPageURL = (window.location != window.parent.location) ? document.referrer : document.location;

Script to get the current page URL/pass the query string from the **Provider hosted app you can use PostMessage API concept**

share|improve this answer
    
There's another answer that suggested this same thing. I left a comment on that talking about why that didn't work. –  Colin DeClue Mar 24 at 19:03

The long and the short of it is, you really can't pass parameters to your app part via a query string. The app part is raised by way of a "redirect.aspx" page which gets rid of any query string params you might send it. Instead, it looks like what you need to do is utilize HTML5 to send a postMessage to the app page. More on how to do this here:

http://mysharepointinsight.blogspot.com/2013/08/how-to-pass-parameters-between-your-app.html

share|improve this answer

Did you try using window.parent?

https://developer.mozilla.org/en-US/docs/Web/API/Window.parent

share|improve this answer
    
If we use window.parent it your sharepoint hosted app, it will give you "Access Denied" error. –  Mihir Jul 17 at 5:30

document.referrer should get you the URL for the page the iFrame is in including the querystring.

share|improve this answer
    
This doesn't work, because it gives an intermediate URL that redirects to the page inside the iframe. It's giving me http://spurl/_layouts/15/appredirect.aspx?redirect_uri= and then some encoded stuff at the end. –  Colin DeClue Apr 11 '13 at 13:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.