|
JAVASCRIPT + IFRAME! please help
04-02-2009, 11:36 PM
|
JAVASCRIPT + IFRAME! please help
|
Posts: 7
|
Hello... I am having trouble with something to do with iFrames and javascript! I am totally stumped on it...and i must finish it!!! :splat::splat:
So, once upon a time... I have an iFrame...
Code:
<iframe src="test.html">
And...I have a javascript function that detects if the `src` has changed of that iframe. All good? No!! When i change the `src` outside the iframe, it works and shows the message I want. But, when i change the url INSIDE the iframe, nothing happens. It's almost like...it doesn't change the src of the iFrame. Please help!
|
|
|
|
04-03-2009, 08:11 AM
|
Re: JAVASCRIPT + IFRAME! please help
|
Posts: 614
Name: Stephanie Kunder
Location: Hanover, PA
|
Link, please? 
|
|
|
|
04-03-2009, 08:23 AM
|
Re: JAVASCRIPT + IFRAME! please help
|
Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
|
If you stay on your domain with the iframe, it should work.
But, if you enter an adress that is outside of your domain, then the cross domain script policies enter in effect and will block the requests from outside the iframe.
Maybe it's what you are experiencing.
Otherwise, rather than referencing iframe.src, try to use iframe.window.location.
It may be that the src of the iframe is not updated when tthe iframe window location object change.
__________________
Only a biker knows why a dog sticks his head out the window.
|
|
|
|
04-03-2009, 05:01 PM
|
Re: JAVASCRIPT + IFRAME! please help
|
Posts: 7
|
@tripy
not quite sure what you mean... do you mean
document.getElementById('myFrame').window.location
window.location(document.getElementById('myFrame') )
document.getElementById('myFrame').location.href
not super familiar with javascript.... but i tried them and nothing seemed to work...
|
|
|
|
04-03-2009, 06:26 PM
|
Re: JAVASCRIPT + IFRAME! please help
|
Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
|
I'll try to play @ home with this too.
Just tell me:
1) which browser you used to test it
2) do you stay on your domain, or does your iframe access a page on another domain.
__________________
Only a biker knows why a dog sticks his head out the window.
|
|
|
|
04-03-2009, 07:00 PM
|
Re: JAVASCRIPT + IFRAME! please help
|
Posts: 7
|
different domain
and
Firefox
|
|
|
|
04-04-2009, 06:54 AM
|
Re: JAVASCRIPT + IFRAME! please help
|
Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
|
Then no need to test.
As I told you in the first post, the cross domain policies restrict you to access the content of the iframe.
It's a security against cross scripting implemented in the browser.
__________________
Only a biker knows why a dog sticks his head out the window.
|
|
|
|
04-04-2009, 11:07 PM
|
Re: JAVASCRIPT + IFRAME! please help
|
Posts: 7
|
then how would it detect if it switched from yahoo to google? they are two domains but my javascript detected it and showed the message i wanted...but when i change the src INSIDE of my iframe...nothing =/
kinda confused.
|
|
|
|
04-07-2009, 03:52 PM
|
Re: JAVASCRIPT + IFRAME! please help
|
Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
|
ok, show me some code, and I'll see what I can do.
But I know one thing for certain: If you have an iframe inside a page, and the iframe is on another domain than your page, then the browser shield the iframe to deny javascript from the page to access what is in the iframe.
__________________
Only a biker knows why a dog sticks his head out the window.
|
|
|
|
04-07-2009, 07:17 PM
|
Re: JAVASCRIPT + IFRAME! please help
|
Posts: 7
|
alls i need to know is if...the user clicks a link in my iframe to goto google, and when it loads google...i need to detect that change of the location...but when i change the URL from inside the iframe...it doesnt detect it. say i have a button that changes the URL from outside of the iframe, it detects it right away....but other than that. im stumped =/
|
|
|
|
04-07-2009, 07:32 PM
|
Re: JAVASCRIPT + IFRAME! please help
|
Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
|
Quote:
|
i need to detect that change of the location...but when i change the URL from inside the iframe...it doesnt detect it.
|
How many time should I tell you:
Quote:
|
the browser shield the iframe to deny javascript from the page to access what is in the iframe.
|
Everything is shielded. Every events, like clicks, url change, mouseover... Javascript variable are too, of course.
This is valid for the url the iframe too (which is the window.location object of the iframe, in fact)
You cannot do that. Point. Final. Forget about it.
__________________
Only a biker knows why a dog sticks his head out the window.
Last edited by tripy; 04-07-2009 at 07:33 PM..
|
|
|
|
04-07-2009, 10:04 PM
|
Re: JAVASCRIPT + IFRAME! please help
|
Posts: 7
|
i can't just forget about it...its a requirement of the website. any other solutions? ^.^
|
|
|
|
04-08-2009, 05:52 AM
|
Re: JAVASCRIPT + IFRAME! please help
|
Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
|
The only one "practical" I know about, is to use a proxy.
The proxy is on your domain, so the javascript request will work, but you will hit many more roadblocks with the proxy...
Relative path, frame busting javascript... A lot of things to take care of.
There might be an half solution though, but not transparent.
The mozilla documentation states that a signed script could ask the permission to the user to enable cross domain javascript requests.
http://www.mozilla.org/projects/secu...nts/jssec.html
But:
1) This is restricted to Firefox users
2) The user must extend his browser configuration by adding keys from the about :config tab
3) The user will be presented a popup asking if the script created by XXX has the authorization to access pages on other domains.
Another one, but highly unpacticable would be to download Firefox sources, and edit the javascript engine to lift that cross domain policy.
But It would mean that only people coming to your site with this specific browser would be able to use your site.
Quote:
|
its a requirement of the website.
|
Well, it's an requirement that cannot be met.
__________________
Only a biker knows why a dog sticks his head out the window.
Last edited by tripy; 04-08-2009 at 05:57 AM..
|
|
|
|
04-08-2009, 09:06 AM
|
Re: JAVASCRIPT + IFRAME! please help
|
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
|
May I ask what your goal is, and why you think you need to be able to read the IFRAME's src? Perhaps there is another solution which you have not considered, because you can forget about this.
|
|
|
|
04-08-2009, 01:23 PM
|
Re: JAVASCRIPT + IFRAME! please help
|
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
|
In addition to everything that's been said, I thought I might take the time to explain why this type of action is blocked.
Let's say a company decides they are going to attempt to track marketing data anonymously without user's consent, so that it may be sold. Now, let's say, for argument's sake, cross-domain requests through IFRAMES was allowed by default. Because links may be programmed with behavior that causes them to open up new IFRAMES, it is possible to make a website look as if it is one thing, but appear to be another, just like a phishing scheme (which it would be).
If an entire browser window was a frame, which in reality existed on your website, and you were allowed to track every change in location to that window, you would be able to track private sensitive information about that user which you should not be allowed to have. This would be absolutely terrible, which is why it is, and should be, blocked.
Last edited by wayfarer07; 04-08-2009 at 01:26 PM..
|
|
|
|
04-08-2009, 04:27 PM
|
Re: JAVASCRIPT + IFRAME! please help
|
Posts: 7
|
click "Click here to download" @
http://sharecash.org/download.php?id=9784
i'm not sure if their advertising agency has soemthing built in that deals with this, but thats the goal.
|
|
|
|
04-08-2009, 04:55 PM
|
Re: JAVASCRIPT + IFRAME! please help
|
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
|
Well, the IFRAME that comes up when you click that link has a URI located on the same domain as the one you linked to, so in that case, information may be passed between the two frames.
From what I can see, everything on sharecash is uploaded to sharecash, and download from sharecase, so I don't see where your question comes in about remote domains?
|
|
|
|
|
« Reply to JAVASCRIPT + IFRAME! please help
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|