I have a form that runs within a frameset from another server. I am trying to figure out how to get the URL of the overall frameset ie. www.mysite.com as there will be different sites displaying this form but I need to determine which site the user is accessing the form from. Is there a quick way to do this?
Subject: RE: Retrieving the URL of main Frameset instead of Document
“Window.top returns [OBJECT]”
Well, sure (but only if you use a lower case w …), and not just any object, but the topmost window object. This window object has a location property again, and this location object has (amongst others) a href property.
So
window.top.location.href
will be the string visible in the browser’s address bar.
Subject: RE: Retrieving the URL of main Frameset instead of Document
Works for me.
Please be a bit more specific about where and how you get that error. It’s probably not written in bold red letters right across your screen.
Is URL an editable field on your form? If you don’t want it to be visible, you cannot just hide it using hide-when-formulas. You need an input of type hidden then. You can create that either manually using pass-through HTML
where [URL] should be computed when composed to URL, or by ticking the form’s property to generate HTML for all fields and hiding the field using hide-whens.
Then my button will not submit and I get an error in the broswer (left hand corner of my IE browser) if I click on this error symbol it says PERMISSION DENIED and will not submit the form.
If I click the PREVIOUS button on this error box it says
document.forms.0.url is null or not an object
Sorry to be such a pain … you’ve been a great help!
Subject: RE: Retrieving the URL of main Frameset instead of Document
The history you need belongs to the window object (top) that you are not allowed to script against. If the referer (the containing frameset) is from a different domain, then you are going to have to capture the referer when your page is initially opened, then pass it around either with a cookie or in the URL. The only way around cross-site scripting security in the browser is to set security so low as to make the browser vulnerable to all kinds of malicious code (IE) or to manually set your domain to have Universal Read privileges, something beyond normal user capability (Mozilla).
Subject: RE: Retrieving the URL of main Frameset instead of Document
As usual, Stan has nailed it. It worked for me, because my little 2-minute-testing was done all on the same server.
Sai, not sure how the architecture for this whole application looks like (sounds a little strange, but you probably know why it’s designed like this). There might be one solution that would take a little less of a hassle. If you have control over the site calling your form, you could have the other side provide some URL parameter to identify itself when calling your form.
If and how much work you could save with that, depends a lot on how much logic follows the original call of your form on your own server and - of course - if you could do it at all.
Subject: RE: Retrieving the URL of main Frameset instead of Document
Thanks for all your input - you all know so much about this. 99% of my knowledge is with writing client side apps not web apps so any input is thankfully accepted.
The referring site will always be one of 3 domains (none of them my own).
Could capturing the history be a way to go as I can always query this information later once the form is saved. Is there anyway to do this?
Subject: RE: Retrieving the URL of main Frameset instead of Document
As Stan pointed out, the history you need belongs to the top window and your JavaScript cannot access that.
Netscpae/Mozilla/Firefox know the concept of digitally signed JavaScript (http://www.mozilla.org/projects/security/components/signed-scripts.html), which would in fact allow you to access the history for other sites (including the top frameset) but there is no directly comparable concept in IE.
Capturing the referrer the first time your site is loaded and then storing it (a cookie would be the easiest way) for future use (because further actions on your page will generate new referrers pointing to your own site) seems like the best approach to me.
Subject: RE: Retrieving the URL of main Frameset instead of Document
thank you - I will try this - I have never used cookies but I will look for information on this.
The reason I thought the history may be a good idea is because I can say to go back 4 pages and that is always the referring page (i use this in my back button) is there a way to get this captured instead of going back 4 pages?
Subject: RE: Retrieving the URL of main Frameset instead of Document
I don’t think so (for the reasons already mentioned).
Cookies can be set either through client side scripting (JavaScript again) or by server side setting of an appropriate HTTP header, which I think should work out for you. This can be done using @SetHTTPHeader, look it up in Designer help. The formula can be placed in any form of computed field on you form. CGI fields sometimes are a little tricky, so make sure the content of the Http_Referer field is really available in your formula.
Likewise, cookies can be read either using JavaScript or using @GetHTTPHeader. Takes a bit of basic string manipulation to get the desired value, but @Formulas are more powerful here than plain JavaScript.
Subject: RE: Retrieving the URL of main Frameset instead of Document
You are running into a cross-site scripting situation, since the code is running from a different server or domain from the frameset it’s looking at. If both are coming from the same domain (just different servers) then you can fix it by explicitly setting the domain property of each document in JavaScript. If the domains are different, you might not be able to get around the problem except by grabbing the HTTP referer and passing it around with a cookie. That will take a bit of doing, too, unless you can always be sure that the frameset domain (or server) is different from the domain you are serving from.
Subject: Retrieving the URL of main Frameset instead of Document
In the form you can use the javascript function location.hostname which should give you for eg www.mysite.com and then determine which site this form is being opened from.
Subject: RE: Retrieving the URL of main Frameset instead of Document
Of the page upon which it rests, yes – but in this case, the page/form will be “hosted” in a frameset served by a foreign server. When the content is originally assembled (that is, when the frameset itself is first opened), one could use the HTTP_REFERER (or @GetHTTPHeader(“Referer”)) to get the hostname of the hosting frameset, but if a click in the frame loads new content, you need to get to the parent window from within the browser – and that means JavaScript.