jpillora / xdomain

A pure JavaScript CORS alternative
https://jpillora.com/xdomain/
3.12k stars 270 forks source link

Feature: Add parent url as param to iframe src #47

Closed amrnt closed 10 years ago

amrnt commented 10 years ago

Before considering this as a feature, I'm trying to find a way to know the current page that the iframe generated on.

In my API, I check for the HTTP_REFERER which will be the /proxy.html, but is there anyway to know whats the parent of the HTTP_REFERER?

So I hacked it to have the iframe src to be /proxy.html?parent=window.parent.location.href and so I can know the parent host of the iframe.

jpillora commented 10 years ago

Could also be a slave option to add an XDOMAIN_MASTER_REFERER header to all requests?

amrnt commented 10 years ago

This would work, but I prefer to have it as a url parameter (or both).

Are you going to implement this (if not already implemented)? I 'hacked' it yesterday on my local machine to have what I want as parameter... What do you think?

jpillora commented 10 years ago

So I had this in the source and was about to push, but realized, if people are doing:

  <script src="http://jpillora.com/xdomain/dist/0.6/xdomain.min.js"></script>
  <script>
    xdomain.slaves({
      "http://xyz.example.com": "/proxy.html?master="+location.href
    });
  </script>

it would break. Which is exactly what you need anyway, without changing the source :)

aseemk commented 9 years ago

Just posting for the record that if you only care about the referring site rather than the referring page (for a single-page app that uses history.pushState, the "page" will change frequently without XDomain getting re-initialized), then use location.origin or location.hostname or etc. instead of location.href.

Also for the record: it'd be sweet if this were an automatic option — and enabled by default! — instead of having to manually opt-in. =) Edit: I assume it wouldn't be a problem if it were the default, since for most people, proxy.html is just a static HTML file.