I've tried a few different things but nothing really worked, basically i need to get the current location/url from the iframe, get the part i want and return it to the hash in the url. how can i do this in javascript?
Asked
Active
Viewed 1.1k times
1 Answers
6
Select the correct iframe element, pull out the src attribute, do your stuff, assign src to window.location.hash
var iframe = $('iframe');
var src = iframe.attr('src');
window.location.hash = src;
EDIT
If you want to get dynamic location from an iframe
you have to access contentWindow
property:
var iframe = $('iframe');
var contentWnd = iframe.attr('contentWindow');
var url = contentWnd.window.location.href;
window.location.hash = url;
also interesting reading on getting the contentWindow property:

Jasper
- 75,717
- 14
- 151
- 146

Juraj Blahunka
- 17,913
- 6
- 34
- 52
-
3The src is not updated when the user is browsing/going to different pages inside the iframe thus it defeats the purpose. any other solutions? – Adam Apr 19 '10 at 22:47
-
2+1 Nice answer, but sadly I think there are still cross domain issues. – Mottie Apr 21 '10 at 14:18