douyimiao1993 2016-03-15 05:34
浏览 99
已采纳

加载外部页面和替换文本

Would it be possible to load an external page inside a container and replace text elements?

We work with ad campaigns and earn a percentage whenever a user signs up.

Can a script replace certain words? For instance “User” to “Usuario” or “Password” to “Contraseña” without affecting the original website or its functions.

Note: These links always pass through a redirection.

Example:

http://a2g-secure.com/?E=/0yTeQmWHoKOlN6zUciCXQwUzfnVGPGN&s1=

Note 2: Using an iframe is out of the question due to “Same-origin policy”.

  • 写回答

5条回答 默认 最新

  • dongyi9082 2016-03-19 20:17
    关注

    I'm not sure if this answers your question, but you might find it useful.

    (Perhaps you might give a step-by-step example of what you're trying to accomplish?)

    If we assume that a browser attempts to retrieve page P from a proxy which first retrieves the content of page P from its actual home and then performs some transformation on its content before returning that page content to the browser, what you're describing is a Reverse HTTP Proxy and is a very well-known page serving technique.

    Rather than performing complex transformations at the server (which require specialized knowledge of the page layout), this technique is usually used to inject a single line into the retrieved source that calls a JavaScript file to actually perform the required transformation at the browser.

    So in essence:

    1. Browser requests Page P from Proxy 1.
    2. Proxy 1 retrieves the actual Page P from its real home, Server 2.
    3. Proxy 1 adds the line <script src="//proxy1.com/transform.js"></script> to the source of Page P.
    4. Proxy 1 then returns the modified source of Page P to Browser.

    Once the Browser has received the page content, the JavaScript file is also retrieved, which can then modify the page contents in any way required.

    This technique can be used to solve your "Same origin policy" issue by loading an iframe from a URL that points to the same server as that which provided the parent or owning page of the iframe which acts as proxy, like:

    http://example.com/?proxy_target=//server2.com/pageP.html
    

    Thus, the browser only "sees" content from a single server.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?