/    Sign up×
Community /Pin to ProfileBookmark

checking if document in iframe is on different server

Hi,

I know that I will get a ‘Access Denied’ if the document inside an iframe is on a different domain. However, is there a way to check if the document is in a different domain?

Basically, I want to do something to the document in the iframe if the document is in my domain, but sometimes there will be documents from other domains in the iframe, in which case I would like to take an alternative action.

Thanks,
Sabretooth

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@sabretooth80authorApr 16.2003 — Thanks, that went a long way toward solving my problem but now I've hit another obstacle. My page has a 'expand' button that allows the content in the iframe to be opened in a new window. Usually, the content in the iframe is from my domain. But if the content contains external links, then the external page gets opened inside the iframe.

If the user clicks one of these external links, I store this external link in a hidden field on my page so I know where the user has gone. So if they click 'Expand' after clicking an external link, I can open the external page by opening the url i stored in the hidden field by checking whether the page is on my server or not using the code supplied above.

However, if the user has clicked a link on the external page and is now on a second external page, is there any way for me to work out the url of this second external page?

I guess one solution would be to open the external link in a new window in the first place but there are other functions on my page that the user may want to perform while looking at the external page so it i feel that it is more user friendly if the external page was inside the iframe.
Copy linkTweet thisAlerts:
@DrDaMourApr 16.2003 — that would be a lot easier to understand if one could see it
Copy linkTweet thisAlerts:
@khalidali63Apr 16.2003 — Here is a simple script that displays how to use exception handling features of javascript properly in your scripts.

http://68.145.35.86/skills/javascripts/ExceptionHandlingJavaScript.html

Cheers

Khalid
Copy linkTweet thisAlerts:
@JonaApr 16.2003 — Hey, I like it! ?
Copy linkTweet thisAlerts:
@khalidali63Apr 16.2003 — ?

Thanks jona,

I hope it helps allots of members out here..

Cheers

Khalid
Copy linkTweet thisAlerts:
@JonaApr 16.2003 — Helped me... I didn't have a question, but the answer was better than expected.. ?

I've never really used throw/catch (or switch, have a script for that?), and that I know of, I haven't needed it. But I may in the future; and I always enjoy learning something new (or something I just skipped because I didn't need it at the time or didn't know about it).
Copy linkTweet thisAlerts:
@khalidali63Apr 17.2003 — I stand corrected,I guess given the history of .....,I just took it too serious..

Cheers

Khalid
×

Success!

Help @sabretooth80 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...