1

I usually use Matlab's internal browser (via, say, the 'web' command), but it has given me a problem by sometimes not detecting when the user clicks next on an online survey I administer through Matlab. I've never had that problem with any external browser (Firefox, Chrome, IE). I want to close the browser automatically when the user gets to the end of the survey. I know the URL that the user will go to after finishing the survey, so can see if the URL of their browser is the one they will be at after finishing the survey. Right now using the internal Matlab browser, I use:

[s,bwser] = web(url2, '-new', '-notoolbar', '-noaddressbox'); 
cloc = get(bwser, 'currentLocation'); 

and then check if cloc is equal to the given URL. I would love to do the same thing with an external browser. I know how to call the external browser and assign it a URL. But how can I retrieve the current URL from that browser after the participant clicks on a link?

4

1 に答える 1

0

You could try this:

function RunSurvey( startURL, finalURL )
    finalURL = lower(finalURL);
    hfig = figure( 'Menu','none','Name','Survey',...
        'ResizeFcn',@reSize,...
        'DeleteFcn',@figDelete);
    hExp = actxcontrol('Shell.Explorer.2',calcSize,hfig);
    Navigate(hExp,startURL);
    while (true)
        pause(1);
        current = lower(get(hExp,'LocationURL'));
        if ~isempty(strfind(current,finalURL))
            break;
        end
    end
    close( hfig )

% Figure delete function
function figDelete(src,evnt)
    hExp.delete;
end

function [size]=calcSize()
        pos = get(hfig,'Position');
    size = [2 2 pos(3)-5 pos(4)-20];
end

function reSize(src,evnt)
  if ~exist('hExp','var')
     return
  end
  move(hExp,calcSize);
end % reSize

end % RunSurvey

Call using:

RunSurvey('www.google.com','www.mathworks.com')
于 2012-09-23T09:43:17.603 に答える