Jump to content

Parent page name of Iframe?


Donar

Recommended Posts

Probably I don't see the tree anymore because of too much forest :)Anyway:A website (not mine) includes an IFrame with the src attribute pointing to an ASP script on my Web server.Let's say the external page is www.someclient.com/somepage.htmlIt contains in its body:<iframe src=MyScript.asp etc.></frame>How can the ASP script tell, on which page that IFrame is located?Thanks in advance!Best regards//Herbert

Link to comment
Share on other sites

in your ASP script use this javascript (client side)

var parentDocument = parent.document;var parentWindow = parent.window;

with those 2 variables you can check anything in the parent's document and window objects.the only possible issue is that this will give an Access Denied error in keeping with cross domain rules.

Link to comment
Share on other sites

Thank you, but...how can my ASP script read the JS variable parentDocument using ASP commands?Regards//Herbert
ASP can't but you could do your checking in JS and use AJAX to send requests back tot he server.
Link to comment
Share on other sites

Sigh. I try to avoid that overhead just to get the page's URL incorporating my IFrame.There really is no other way to obtain that URL which is present everywhere, just with standard JS and ASP? No way to pass a parameter to the src attribute of IFrame?I try to explain some more as for the purpose:My ASP Script is a working utility showing where the last page vistors came from. It runs stable and all, but in a IFrame. Understandably I want avoid that anyone can copy the IFrame code and use it on his own pages, thus interacting severely with the original user's data, being of no benefit for both. Therefore, I wanted to couple functionality with the originating webpage: the ASP script is to check the calling webpage and accordingly updates the correct data.Well, thanks anyway for suggesting your solution, aspnetguy.Herbert

Link to comment
Share on other sites

Have you checked what data is being sent with the Request for your asp page? Perhaps there is a header in the Request which contains the data that you are looking for - perhaps the Referer? I don't play much with frames so I don't know if the referrer information will contain the URI of the last page the visitor visited or if it would contain the URI of the parent frame. I'm sure it's worth a shot.

Link to comment
Share on other sites

Hello Jesh,yes, I have tried to loop over all server variables. All I get is the user's IP, ther server's (my own) IP/Name, the ASP file's name and its physical location (on harddisk), but not a single clue about the page in which the IFrame is contained: the IFrames' src (the ASP file) acts as if it was the destination page directly typed in by the surfer.

Link to comment
Share on other sites

I found a quite trivial solution. It works for IE and Firefox, not sure about other browsers.In the client, I first declare an IFrame displaying an empty page. Immediately after that, a JS is executed, basically like this:

<iframe id="hsacities" name="hsacities" src="blank.html"></iframe><script type="text/javascript" src="display.js"></script>

The JS simply reads:

document.getElementById("hsacities").src = 'MyASPScript.asp?'+window.location;

Then, on the server side, I can extract the origin with:

fromsite = Request.ServerVariables("QUERY_STRING")

Now it's an easy task to assign a userid as per variable fromsite and query only the according records.Of course, this is not foolproof: I am aware that ynyone could copy the JS "file" and modify it to submit an approved page. However, besides that he increases the legit user's data no harm is done: and especially is he not able to use the script for own purposes. Maybe I find a way around this as well one day :)Thanks to all for your suggestions, helped me on the way to find a solution (sometimes it's the half way to have someone to share the problem with). If someone is interested in how the script looks like (or even wants to tell me about the appearance in other browsers) I'd be glad to give you the URL :)Regards//HerbertPS: No way to make above Codeboxes smaller?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...