Search code examples
htmlcross-domainjsonp

get html input field value from Cross-Domain using jsonp


Trying to retrieve the value of a input field in a external site's webpage. They wont change the headers. So been told to use Jsonp. Never used this. Anyone have any examples or can point me in the right direction?

Outline: External Site:

<input type="hidden" id="ImHiddenGetMe" value="Get Me If You Can">

Cannot use ajax/jquery as they wont change the headers to allow the cross domain.


Solution

  • For using JSONP the other server must provide an interface to it. For example: The other server must provide an URL like

    http://other.com/getvalue?jsonp=callbackFunction
    

    This URL must sent JavaScript code like

    callbackFunction({ value: "Get Me If You Can" })
    

    If the other server does not provide such an interface and do not provide the Access-Control-Allow-Origin Header necessary for Cross origin resource sharing you cannot load the other site via AJAX.

    But you can always program a crawler which stores the value periodically on your server (where you can use it). Please respect the other server's robots.txt in this case.