check for location url once a link in a website is clicked
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
I am trying to make a gui for downloading data from the web after specific user selections.
to do this I would like to check the url every time a mouse is clicked (is there a better way to get the location every time)?
I found a code that prepares the gui:
% Create a blank figure window
f=figure('Name','Browser GUI demo');
% Add the browser object on the right
jObject = com.mathworks.mlwidgets.html.HTMLBrowserPanel;
[browser,container] = javacomponent(jObject, [], f);
set(container, 'Units','norm', 'Pos',[0.3,0.05,0.65,0.9]);
% Add the URLs listbox on the left
urls = {'http://mcm.leeds.ac.uk/'};
hListbox = uicontrol('style','listbox', 'string',urls, ...
'units','norm', 'pos',[0.05,0.05,0.2,0.9], ...
'userdata',browser);
% Set the listbox's callback to update the browser contents
cbStr=['strs = get(gcbo,''string''); ' ...
'url = strs{get(gcbo,''value'')};' ...
'browser = get(gcbo,''userdata''); ' ...
'msg=[''<html><h2>Loading '' url '' - please wait''];'... % no need for </h2></html>
'browser.setHtmlText(msg); pause(0.1); drawnow;'...
'browser.setCurrentLocation(url);'];
set(hListbox,'Callback',cbStr);
and I want to add an if statment with the "mouse clicked event" and in it to write:
browser.getCurrentLocation
Please help me, I can't figure out how to know if a link was pressed.
2 commentaires
Geoff Hayes
le 15 Juin 2020
daphne - how would you like to use the if statement because it isn't clear to me how. Also, rather than creating a string for your callback, just define another function...though depending upon your version of MATLAB you may need to put your above code within a function (rather than a script) so that you can define the callback function too. For example, the following code would be saved to a file named myUrlDownloadExample.m
function myUrlDownloadExample
close all;
% Create a blank figure window
f=figure('Name','Browser GUI demo');
% Add the browser object on the right
jObject = com.mathworks.mlwidgets.html.HTMLBrowserPanel;
[browser,container] = javacomponent(jObject, [], f);
set(container, 'Units','norm', 'Pos',[0.3,0.05,0.65,0.9]);
% Add the URLs listbox on the left
urls = {'http://www.google.ca/'};
hListbox = uicontrol('style','listbox', 'string',urls, ...
'units','norm', 'pos',[0.05,0.05,0.2,0.9], ...
'userdata',browser);
% Set the listbox's callback to update the browser contents
set(hListbox,'Callback',@listBoxCallback);
function listBoxCallback(hObject, eventdata)
strs = get(hObject,'string');
url = strs{get(hObject,'value')};
% browser = get(hObject,'userdata');
msg=['<html><h2>Loading ' url ' - please wait'];
browser.setHtmlText(msg);
pause(0.1);
drawnow;
browser.setCurrentLocation(url);
end
end
Réponses (0)
Voir également
Catégories
En savoir plus sur File Operations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!