Passing parent URL string to javascript

I need to be able to pass the parent url's string into a piece of javascript that is contained in an iframe on the same page

In particular, with the following

<script type="text/javascript">
digg_url = 'WEBSITE_URL';
digg_bgcolor = '#ff9900';
digg_skin = 'compact';
</script>
<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script>

WEBSITE_URL needs to be the parent url programmitically, so that the Iframe can be used on any page

Anyone know how this can be accomplished?
cdr21Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GitchoCommented:
from within the iframe, use parent.location.href.   eg  :
alert(parent.location.href);
0
Yury MerezhkovDevelopment Team LeadCommented:
digg_url = document.URL;
0
GitchoCommented:
if you use document.URL within the <iframe>, it will give you the URL of the iframe, not the parent.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Yury MerezhkovDevelopment Team LeadCommented:
Gitcho, good to know!
0
neeraj523Commented:
I guess Gitcho is right..

more precisely u need to edit ur code like this

<script type="text/javascript">
//////////
digg_url = parent.location.href;
//////////////
digg_bgcolor = '#ff9900';
digg_skin = 'compact';
</script>
<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script>

neeraj523
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cdr21Author Commented:

Unfortunately, even

digg_url = parent.location.href;

Is not working in this case.

The parent URL I'm testing with is:

http://www.kait8.com/global/Story.asp?s=6289742

The iframe block is just below the story body, titled 'Share this Story'

Any more ideas

-cdr
0
GitchoCommented:
ahhh ... ok ... I could be wrong, but it appears your <iframe> source is from a different domain.  Parent window information isn't available when the parent window is on a different domain - this is a security restriction by design ... that's why you're getting the "uncaught exception: Permission denied to get property Location.href" browser errors .

If you need your diggthis button in the iframe, you'll have to hard-code the referring href, because you won't be able to get it with javascript.
0
cdr21Author Commented:


In this case, within this content management application I am 'tied' to, I really need to somehow get the parent URL info into the Iframe by passing a parameter of some sort.

If not javascript itself, can ASP or PHP be used to 'pull' 'referring' URL info and be transferred to a javascript variable once inside the Iframe?
0
neeraj523Commented:

Alternatively, you can pass the parnet URL into frame page as querystring().. Which u can read in frame page using request object or even using javascript..

something like this in parent page

<iframe src="myFramePage.asp?parentUrl=<%=Request.ServerVaraibles("URL")%>"></iframe>

dont know if it help u out..

neeraj523
0
cdr21Author Commented:
thanks for your idea neeraj523... I finally found some time to try it, but it only passes the URL of the iframe itself again...

Alternatively, I can just construct a string of the form:

http://digg.com/submit?phase=2&url=example.com&title=TITLE&bodytext=DESCRIPTION&topic=TOPIC and use a button in the iframe to submit it.
How do I use parent.location.href to in pass the parent url in the url=example.com portion of the querystring above?

0
neeraj523Commented:

cdr21.. i still believe the solution i provided should work.. <%=Request.ServerVaraibles("URL")%> should give the parne page url if written in the parnet page..

Make sure u r writting it in the parent page where u adding iframe
0
cdr21Author Commented:
I tried using ASP and the ServerVariables object in the querystring several different ways from the parent page like:

<IFRAME style="WIDTH: 341px; HEIGHT: 160px" name=ShareThisBox marginWidth=0 marginHeight=0 src="http://go.kait8.com/sharethis/K8is_sharethis2.asp?parentURL=<%=Request.ServerVariables("URL")%>" frameBorder=0 noResize width=400 scrolling=no height=160></IFRAME>

The following string appears in Digg.com as the one to 'share':
http://go.kait8.com/sharethis/K8is_sharethis2.asp?parentURL=

In the parent frame I have also tried enclosing the URL parameter in single quotes, like ('URL') and no quotes (URL)... the same string above keeps appearing...

Since the string is cut off where the first ASP marker appears, I'm assuming that the web content platform I'm working with does not support passing ASP marked up info in a query string.
0
cdr21Author Commented:
Also this week I have tried to circumvent the cross-domain security that Gitcho mentioned earlier.  

I moved the iframe to a subdomain and set the javascipt document.domain in the iframe to:

document.domain="kait8.com";

Still no luck...
0
cdr21Author Commented:

I was able to finally it working using the parent.location.href variable assignment and moving the  iframe to a a subdomain location

thanks all!

-cdr
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.