JQuery Get Parent URL in IFrame:iframe and its parent are in Different domain

Charlie

I am struggling to get parenet URL inside my iframe (ie the url showing in browser). My parent site is gslb13.aaa.com .Inside there is an iframe in which i am loading my site test.elasticbeanstalk.com (notice both are in different domain) Onclicking smile link in gslb13.aaa.com. It will load test.elasticbeanstalk.com inside iframe.

To get the parent url I tried with

var url = (window.location != window.parent.location) ? document.referrer: document.location;
alert(url);

I am getting the parent URL in index page of test.elasticbeanstalk.com (on load). then:

1) I clicked "Add" buttons in the test.elasticbeanstalk.com to go to next view

2) Repeated the same code in add.jspx to get the same parent URL

But unfortunately I am getting the URL of test.elasticbeanstalk.com(Not Parent URL:gslb13.aaa.com )

Can Any one suggest me a way to handle this?

Tschallacka

You cannot.

The same origin security rules prohibit it. http://en.wikipedia.org/wiki/Same-origin_policy

You need to pass the URL of the parent page with the get request, ortherwise there is no reliable way to get the "parent" url.

You would need the iframe like this:

<script type="text/javascript">
url = encodeURIComponent(document.location.href);
document.write('<iframe src="http://test.elasticbeanstalk.com/something.php?refer='+url+'"></iframe>');
</script>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Get javascript variable in an iframe from parent window in a different domain

From Dev

How to get the parent window URL from Iframe?

From Dev

How to get the parent window URL from Iframe?

From Dev

How can an iframe get its parent background color?

From Dev

Fancybox (jQuery) - Passing information from parent to iframe and iframe back to parent

From Dev

How to just scroll the iframe but not its parent?

From Dev

Accessing a tag from an iFrame to its parent

From Dev

Resize iframe and its parent height according to content inside iframe

From Dev

Change parent window URL from iFrame

From Dev

Accessing Parent global variable in iFrame url

From Dev

targeting element in parent window from iframe with jquery

From Dev

Click a class in iframe to execute parent jquery

From Dev

Get parent iframe element by an element located within an iframe

From Dev

Get innerText from iframe from parent

From Dev

Get the height of a same domain iframe when that iframe is inside a different domain iframe?

From Dev

Hide a div in the parent of an iframe

From Dev

Apply a parent to an iframe

From Dev

Getting parent value in an iframe?

From Dev

iframe append to parent

From Dev

javascript: reestablish parent for iframe

From Dev

scrolling iframe with parent window

From Dev

Detect click in iframe and run script in parent (NOT same domain)

From Dev

How to make width and height of iframe same as its parent div?

From Dev

How to copy a cloned node in an iframe to its parent with styles?

From Dev

Does jQuery inside an IFRAME affect the parent window's jQuery?

From Dev

Does jQuery inside an IFRAME affect the parent window's jQuery?

From Dev

Possible to access a function on a parent page from an iframe that is on a different subdomain?

From Dev

Possible to access a function on a parent page from an iframe that is on a different subdomain?

From Dev

AJAX request from iframe, why is the origin the parent's URL?

Related Related

  1. 1

    Get javascript variable in an iframe from parent window in a different domain

  2. 2

    How to get the parent window URL from Iframe?

  3. 3

    How to get the parent window URL from Iframe?

  4. 4

    How can an iframe get its parent background color?

  5. 5

    Fancybox (jQuery) - Passing information from parent to iframe and iframe back to parent

  6. 6

    How to just scroll the iframe but not its parent?

  7. 7

    Accessing a tag from an iFrame to its parent

  8. 8

    Resize iframe and its parent height according to content inside iframe

  9. 9

    Change parent window URL from iFrame

  10. 10

    Accessing Parent global variable in iFrame url

  11. 11

    targeting element in parent window from iframe with jquery

  12. 12

    Click a class in iframe to execute parent jquery

  13. 13

    Get parent iframe element by an element located within an iframe

  14. 14

    Get innerText from iframe from parent

  15. 15

    Get the height of a same domain iframe when that iframe is inside a different domain iframe?

  16. 16

    Hide a div in the parent of an iframe

  17. 17

    Apply a parent to an iframe

  18. 18

    Getting parent value in an iframe?

  19. 19

    iframe append to parent

  20. 20

    javascript: reestablish parent for iframe

  21. 21

    scrolling iframe with parent window

  22. 22

    Detect click in iframe and run script in parent (NOT same domain)

  23. 23

    How to make width and height of iframe same as its parent div?

  24. 24

    How to copy a cloned node in an iframe to its parent with styles?

  25. 25

    Does jQuery inside an IFRAME affect the parent window's jQuery?

  26. 26

    Does jQuery inside an IFRAME affect the parent window's jQuery?

  27. 27

    Possible to access a function on a parent page from an iframe that is on a different subdomain?

  28. 28

    Possible to access a function on a parent page from an iframe that is on a different subdomain?

  29. 29

    AJAX request from iframe, why is the origin the parent's URL?

HotTag

Archive