Reputation: 11
I've tried to look for an answer in the posts, but still don't have a clear one. This is my scenario: on one of the pages I have an IFRAME that is getting content from another domain. The frame looks odd, the style is totally different from the main site. On top of that by submitting the form it targets new page and I’d prefer the user to stay on the same page. So I thought maybe I can change a few things - styling and the target of the form within that IFRAME. As far as I understand it is not possible by using JavaScript since it’s coming from another domain. I was thinking about server side script (PHP for example) that would load IFRAME content into a string first and then replace style href’s, change "target = _blank" to something else and finally pass the content back to the page.
This is what I have in mind. Originally it looks like this:
<!-- iframe src="http://www.otherdomain.com/cgi-bin/querypackage.cgi?code=ent1"></iframe-->
I replace it with this:
<iframe src=”frameprocessor.php"></iframe>
All the magic happens in frameprocessor.php.
Is it possible? Maybe I’m overcomplicating things and the answer is much simpler……
Thank you!
Upvotes: 0
Views: 1936
Reputation: 1159
You can not modify the contents within an iFrame. Especially it's contents and forms. You can alter the outter appearance (ie; the height/ width/ borders, etc...) But due to XSS issues (https://www.owasp.org/index.php/Cross_Frame_Scripting) - you wont be able to modify content within the iFrame.
What I do suggest however, is maybe an API request to the domain? Or maybe building a cURL solution to post data into the website through an external form (webhooks).
Upvotes: 1
Reputation: 626
Just shooting in the dark here, but try using contentDocument of the iFrame object?
http://www.w3schools.com/jsref/prop_frame_contentdocument.asp
EDIT: since you've added the idea of using php, you could use get contents through php to fetch the page and alter the stuff you want to change and output the delta.
I'm kinda curious if the contentDocument thing would work though, I've never personally tried that (i shy away from iFrames!)
Upvotes: 0