Restricting my site to use other domains url in iframe
How I restricting my site to use other domains url in iframe.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
AshishRank #8,652 · 218 reputationPosted Apr 16, 2014, 9:38 PM EDT
Priti KumariRank #414 · 6K reputationPosted Apr 16, 2014, 10:21 PM EDT
AshishRank #8,652 · 218 reputationPosted Apr 16, 2014, 10:44 PM EDT
Thanks,
Ashish
Priti KumariRank #414 · 6K reputationPosted Apr 16, 2014, 10:51 PM EDT
when i load my web page then my url is like:http://mydomainname/page/mypage.aspx
in mypage.aspx one iframe, in this iframe my another page load dynamicaly according to user click on some specific link.
so my parent url http://mydomainname/page/mypage.aspx not change but my iframe page is change every time according to user click.
In above condition when i add another site url to my iframe src then its load another site to my web site iframe.so i want to restrict this .please help me......
AshishRank #8,652 · 218 reputationPosted Apr 16, 2014, 11:00 PM EDT
Am i right?
Working on this give me some time.
Priti KumariRank #414 · 6K reputationPosted Apr 16, 2014, 11:05 PM EDT
Priti KumariRank #414 · 6K reputationPosted Apr 16, 2014, 11:06 PM EDT
AshishRank #8,652 · 218 reputationPosted Apr 16, 2014, 11:19 PM EDT
My Site Scene is like this:
when i load my web page then my url is like:http://mydomainname/page/mypage.aspx
in mypage.aspx one iframe, in this iframe my another page load dynamicaly according to user click on some specific link.
so my parent url http://mydomainname/page/mypage.aspx not change but my iframe page is change every time according to user click.
Case 2:
In above condition when i add another site url to my iframe src then its load another site to my web site iframe.so i want to restrict this .
Q1) Is your Case 1 working ?
Q2) When you want to restrict another site url in your Iframe, then why are you setting src to that site. ?
Because its browser feature to show the requested page in Iframe.
Priti KumariRank #414 · 6K reputationPosted Apr 16, 2014, 11:27 PM EDT
Priti KumariRank #414 · 6K reputationPosted Apr 16, 2014, 11:33 PM EDT
AshishRank #8,652 · 218 reputationPosted Apr 16, 2014, 11:36 PM EDT
if (window.top.location.host != "mydomainname")
{
document.body.innerHTML = "Access is not allowed";
}
ADD above javascript in your code and tell me .....
AshishRank #8,652 · 218 reputationPosted Apr 16, 2014, 11:44 PM EDT
you can do this by inspecting the referer property.
Request.UrlReferrer
See that it contains the domain that you want to allow. This property is available when an embedder puts your page in the IFRAME's SRC attribute and the
page loads for the first time
Vivek Arya20 reputationPosted Apr 16, 2014, 11:54 PM EDT
Priti KumariRank #414 · 6K reputationPosted Apr 17, 2014, 12:22 AM EDT
Priti KumariRank #414 · 6K reputationPosted Apr 17, 2014, 12:23 AM EDT