I have a button that goes to a page and that page generates a url to copy and paste.

Is there a way that I could load that page and access the html to parse out the url and go directly to that url?

I read on jQuery load and get functions and they do not support cross domain loads. I also thought I could maybe use an iFrame to load the document then use jQuery to parse the page that way, but salesforce doesn't load iFrames due to clickjacking.

Can anyone think of a way to get around this issue?


I believe you can do this on the server-side in Apex providing you have created a remote site setting to allow access. To work with an apex:commandButton the code would look like this:

public PageReference redirectToParsedUrl() {
    HttpRequest req = new HttpRequest();
    HTTPResponse res = new Http().send(req);
    if (res.getStatusCode() == 200) {
        String html = res.getBody();
        // Do your parsing
        String url = ...
        return new PageReference(url);
    } else {
        // Error handling

or you could expose it as a WebService method and use a JavaScript button.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.