In my page i have iframe code. When i click particluar link that i frame window enabled.it is a form.when i submit the form i get some hidden field values.how can i access those values in my parent page?.
Since your iframe src= a complete url, and not a relative path (i.e: /app/appsignup.jsp) I am going to assume this Iframe exists at another IP or domain than the original page. If this assumption is correct, then you are not going to be able to modify the Iframe's DOM due to cross site scripting security rules in most browsers.
If the parent site, and child iframe exist on the same top level domain, then you can use document.getElementById("iframe_id")
Edit to answer second question:
You can add an onLoad event to the iframe, and so long as the iframe only has 1 form, and the page only changes when submitted, and this is where you want to be redirected.
Here is an example, but know this will redirect the first time and not work!
What you will want to do is put a function in there, and then in the .js for that function check for the second onLoad...
<iframe name="signUp" id="signup" src="10.80.32.9:8080/app/appsignup.jsp"; width="650" height="500" onLoad="window.location('/index.html');">
You will not be able to access the iframe if it's on a different domain and/or port, as yours seem to be. The Same Origin Policy will prevent that.
There may be a workaround, depending on your use case. Maybe add some more details.
Related
I have iframes on my website which point to content on a different domain. This content is meant to be re-purposed and is ad supported. There is 3-5 ad's on each page, each with their own close button. I believe they are all in one div, id="bannerfloat22". Is there a way to make a close button but target the div inside the frame? The codes I've tried only seem to work if the div is on MY page.
Example: I use this iframe on my page.
<iframe src="http://coolsport.tv/kiwi25.html" name="25" width="650" height="480"></iframe>
Thanks.
If the iframe url is a different domain, then no - there is nothing you can do. If the iframe url is from your site's domain, then yes - you can target the DOM inside the iframe.
In short... No. Javascript from one domain cannot have any control over a DOM from another. This is a security issue - eg to stop a hidden iframe stealing login details for another site
For more information, read up on the same origin policy
I have a rotator link and I dont want to allow people to open it in iframe.
How to stop php process in iframe?
header("X-FRAME-OPTIONS: DENY");
does not work in firefox and chrome. my link is (EDITED)
Check the Access-control-allow-origin header.
It allows you to control which domain can access or frame your scripts.
You can choose between 3 values :
Only from the same domain
Only from a domain listed on a list you made
From anyone (wildcard)
Since PHP is never in an iframe but executed on the server side there is no way to reliably know if the request originated from an iframe on your site of not.
If your intention (which is not quite clear) is to make sure people don't put an iframe of your site on another site, then you can check for the referrer of the request etc. But most of it can be spoofed.
Update due to comment:
Then there is unfortunately no good standardized way of getting this type of information reliably. If you yourself had an iframe on your site and for some reason didn't want that to be able to call your script you could probably do this by adding some GET parameters via javascript or something. But since you have pretty good control over your own iframes this shouldn't be a problem.
But when it comes to determining of the request from the browser to your server originated in an iframe or not there is no information in the HTTP header to disclose this. The only thing you could possibly be informed about is if that iframe is from a page hosted on another domain.
But if you have an iframe on your own site, don't add any extra parameters to the request and access your script in it and then normally from the browser's main window the two requests will look the same on the server.
I'm not completely sure if I understand your question, but here's a list of things:
If you want to stop your page being loaded in an iframe, there's not easy way of doing that, if the browser is ignoring X-Frame-Options: DENY.
If you have a link the user can click that opens in the iframe, not the parent frame, you can use the base html tag, to specify to the browser to open any links you click in the parent frame, with <base target="_parent" />
If you want to redirect automatically, and that causes an issue when loaded in an iframe because you use headers to do it or something, you could probably use the base tag and some javascript to automate clicking on the link as an alternative
Similar to Stumbleupon, if you load random domains (ones that I do not own) and want to have the links within that page not just change within the iframe, but change on the parent url.
If that's hard to understand here's more layman terms:
URL: mywebsite.com/reddit.com
opens iframe on my website showing: reddit.com
click link within the iframe (showing reddit.com).
rather than it loading the new page in the iframe, can it load in the parent window at mywebsite.com/reddit.com/newlink
which would then open the iframe in my website, but would allow me to track what URL is being view and thus allowing me to perform my site-specific functionality.
Thanks!
in short, it cant happen. external sites are made to open links relative to their sites. there is no way to accomplish this.
you can set the link target to _top. <a href='www.someothersite.com' target='_top'>Link</a>
edit: Sorry, mis-read something. You can not edit the page on the other site through the iframe to change the target of the links. This is why on places like google images or stumbleupon they have an "X" in the corner that takes you to the page in the iframe.
If you could modify external pages, that would be a major phishing security risk as anyone could then make a page that is just an iframe to your bank but collects whatever you type into the username/password boxes.
In the old days if you made a page with frames you could specify what section your links took you to. Modifying links that aren't under your control is possible but rather a task and a half.
To use frames you could specify your target= within your tag. Each frame is named on creation to make it easy.
That's an old approach. Hope it helps
I'm creating a website where users enter a URL and it's displayed in an iFrame, to be brief. I know a lot of websites have code to break out of iFrames (popular example, Google).
Is there any way to check, with JavaScript or PHP whether a given URL will break out of an iFrame?
As a side-note, I don't mind taking a website snapshot but I haven't found an existing adequate website and I can't seem to install wkhtmltoimage/pdf...but that's a different question.
So long as the iframe's URL is different to that of the parent (your website) the iframe's JavaScript cannot access anything in its parent.
For cross-domain iframe communication to work one might use HTML5's PostMessage (which has decent support as of right now) or passing params via the URL of the iframe.
Both of these methods require the parent (your website) to explicitly intercept the 'calls' from the iframe and do whatever...
All in all, for security reasons an iframe from an unknown source can't simply alter the parent site holding the iframe.
Here's the situation.
I have a site where clicking hyperlinks within a certain div makes a jQuery function get the content of a div from a separate page. Because of this, the URL don't change. I need it to change as well as writing an entry in history.
My pages are setup like this (not sure this is the smartest way of going though)
access.php (main logon)
new-user.php
forgot-pass.php
index.php
controlpanel.php
etcetc. Now, all of these pages are reachable on their own and are mainly identical and all contain a div called "container". When clicking links, the content from this div gets erased and the content from the coresponding div (container) gets loaded from the file of the URL (href). I'm terrible at explaining..
So basically, what I need is some javascript that picks up the href link address and just pastes it in the url bar at the same time as it creates an entry in history so the back and forth buttons work.
I plan on extending this in a while as well, translating query strings as well. But there are a few constant static pages I need to take care of first. Any help would be very appreciated! :)
You are not allowed to change the entire URL by JavaScript but you can use URL hashes. I recommend you the browser history plug-in. You can simply register a handler to react on URL changes and load your corresponding content via ajax.
Have you looked at the jquery address plugin? Look at the examples. Is this similar to what you want?
It's not possible with "normal urls" (we must wait for a new generation of browsers...)
But there is a "trick": playing with anchors.
A link like "same_page.php#anchor" does not reload the page, but act on both the history and the adress bar.
So, if instead of having url like "page.php?param=lorem", you could have "page.php#param=lorem", you have your solution :)