Website im iFrame

B

Benutzer007

Hallo,

mit folgendem Script verhindere ich Moment, dass andere meine Website - MeineWebseite.com - im iFrame laufen lassen:
Javascript:
if (top != self) {
    top.location = self.location;
}

Nun will ich die Seite aber selbst innerhalb einer anderen Website von mir - MeineAndereWebseite.com - im iFrame laufen lassen. Wie mache ich das, ohne dass alle anderen daselbe tun können?

Grüße

PS: Unabhängig von dem Gesagten, hat einer eine Ahnung, wie ich Googles Analytics - vermutlich setDomainName() - einsetzen würde, um zu erreichen, dass der Aufruf des iFrames gezählt wird? Der Grund ist, dass die top Domain dann ja nicht MeineWebseite.com wäre sondern MeineAndereWebseite.com.
 
Zuletzt bearbeitet von einem Moderator:
Du musst doch nur Abfragen, ob die einbindende Seite auf einer von Dir definierten Whitelist steht und gut ist.
 
Schon klar, aber wie mache ich das?

Ups, ich glaube nun habe ich es gefunden: http://www.nczonline.net/blog/2013/04/16/getting-the-url-of-an-iframes-parent/ Ich hatte des nämlich schon mal gefragt und keine Antwort bekommen.
When a page is running inside of an iframe, the parent object is different than the window object. You can still access parent from within an iframe even though you can’t access anything useful on it. This code will never cause an error even when crossing origins.

Once you know you’re in an iframe, you can take advantage of a little-known fact: the HTTP Referer header for a page inside of an iframe is always set to the containing page’s URL. That means a page embedded in an iframe on http://www.nczonline.net will have a Referer header equal to that URL. Knowing this fact, you need only use the oft-forgotten document.referrer property. As the name suggestions, this property contains the value of the Referer header for the given document. So you can get the URL of the iframe’s parent page like this:
Javascript:
function getParentUrl() {
    var isInIframe = (parent !== window),
        parentUrl = null;

    if (isInIframe) {
        parentUrl = document.referrer;
    }

    return parentUrl;
}
 
Zuletzt bearbeitet von einem Moderator:

Neue Beiträge

Zurück