2

I'm actually trying to find a way to load an iframe content trought proxy in order to bypass the same origin piracy, but in JavaScript. I want to make a UserScript in fact and i'm kinda new in this usercripting. It basicly uses Javascript.

Right now i'm adding an iframe of a forum from a different domain and thing is that i don't want to display everything from this forum just the table part (like get rid of menus, footers, headers, etc). So in order to do this i need to change the content of my iframe, but due to same origin policy it isn't possible as it's not the same domain.

I've search for some solutions and getting trough a proxy seems to be the best bypass way to achieve what i'm trying to do. But now, this bypassing with proxy works with php. And useScripts are codded in JavaScript.

how can i load my iframe through a proxy using JavaSCipt then? From what i get i need to serve the iframe from the same domain as the webpage where my userscript is executed. The website where the userscript is executed isn't mine, but i can modify DOM content in everypossible way thans to this userScripting. But i don't know if this is even possible with UserScripts and how to achieve this :(

Will it allow me to change my iframe content? I only want to change the CSS and be able to read (not write) some of the content.

Any Jquery solution is welcome

Pls help, thank you!

PS: Sorry for any mistakes, trying my best to explain clearly my problem

Mario R.
  • 81
  • 11
  • A proxy runs on the same server your script runs on or a server where you can establish CORS. Apart from that, make sure the TOS of the site you want to frame allows you to do so – mplungjan Jan 22 '15 at 07:35
  • @mplungjan but is it possible to achieve this with a UserScript? Can i have an example of the code? I can't find anything about this on the internet :/ – Mario R. Jan 22 '15 at 07:37
  • A user script does not need a proxy. It should be able to remove all the stuff when the page loads - http://stackoverflow.com/questions/11638595/how-do-i-access-an-iframes-javascript-from-a-userscript – mplungjan Jan 22 '15 at 07:38
  • @mplungjan Even if i can modify the dom with the userscript i can't modify the iframe content. I tried the same way he does but the difference with me it's that i'm doing it cross domain. That's why i'm searching for a way to load my iframe content through proxy using the domain of the website where it is loaded. I can't modify anything with `.contents()` it does nothing – Mario R. Jan 22 '15 at 07:47
  • @mplungjan idk if i got it right, but if i add an include statement of the frame src should i be able to modify the DOM of the iframe? Is this what you mean? – Mario R. Jan 22 '15 at 07:48
  • if you set `document.domain` inside the iframe to match the domain you want to use it on you can do what you want. Can also use `postMessage` API to communicate between the 2 windows. You could also use php to remove parts of the page you don't want – charlietfl Jan 22 '15 at 07:49
  • @charlietfl How cna i set the document domain of the iframe? It's not my website. All i can do is use userscript. I can't change anything on both pages from internal point of view. I can only play around with UserSCript. If you have any example of that i would appreciate. For both of your solutions i need an internal coding on both webpages, which i can't do : – Mario R. Jan 22 '15 at 07:51
  • you said you were setting up a proxy on your domain using php. If you do that you control the source of iframe and can add the script tag to the scraped page. If you have no access to this proxy you can't do any of what you are asking – charlietfl Jan 22 '15 at 07:52
  • @charlietfl no no, i don't do that. I said this is how it works with php and i want to do the same with my userScript which is in JavaScript language. Reread my question : – Mario R. Jan 22 '15 at 07:54
  • Can't access iframe then. Best you could do is use a third party proxy service to scrape some data from the other page and insert that into the page you want to view it on – charlietfl Jan 22 '15 at 07:55
  • Yeah it's what i want to do but i don't know how ^^' – Mario R. Jan 22 '15 at 07:57
  • can use Yahoo's YQL to get data – charlietfl Jan 22 '15 at 08:01
  • UserScript on Greasemonkey has `GM_xmlhttpRequest` API which can access cross domain resource directly. Is this what you need? – tsh Jan 26 '15 at 04:25
  • @tsh I've tried this but it doesn't work. But actually the solutions is to simply add an inlude of the other website and that's it. Then you can still grant GM_XmlhttpRequest if you want to make some cross-domain request but even without it you still can change the DOM of your iframe. I don't get why it isn't allowed with normal JavaScript when UserSCript can manipulate cross-domain requests so easily. – Mario R. Jan 26 '15 at 07:21

0 Answers0