Jim1 Posted July 26, 2009 Posted July 26, 2009 Hi, Has anyone built any custom functions or does anyone know of a way of how to get all the URLS/links from a text field or web viewer within FileMaker 10? Many thanks for any suggestions... Jim.
bcooney Posted July 26, 2009 Posted July 26, 2009 Well, the GetLayoutObjectAttribute ( "webViewer" ; "content" ) will grab everything, and then using Patterncount( ) and Position ( ) you can parse out what you need.
Jim1 Posted July 26, 2009 Author Posted July 26, 2009 Thanks. I know how to grab everything from the webviewer, and I did consider the patterncount, but I just didnt want to go down the route of iterating through all of the page when I find a 'www' pattern, then work left/right of the pattern until the end of the URL. I think within FileMaker that this may be the only way of acheiving what I want. Thanks. Jim.
bcooney Posted July 26, 2009 Posted July 26, 2009 I thought that you might be aware of the function, and I didn't see any CFs that would help on Dunning. Oh well.
fseipel Posted July 27, 2009 Posted July 27, 2009 (edited) Yes, it's a big pain to iterate through the HTML source to find tags or links; I've done it myself. Another alternative is to inject a single line of Javascript into the webviewer after the page loads. This is possible by setting the URL to javascript: followed by the javascript. You can try it in your browser right now, without Filemaker. Setting your browser address bar to the code below will cause immediate execution of the script: javascript:text=' '; for (i = 0; i <= (document.links.length-1); i=i+1) {text= text + "#" + i + " " + document.links[i].text + " ";} document.location.href="data:text/html," + text; Above will generate a numbered list of all links on the currently loaded page. Above lists link text; if you want link URL's, just omit the .text suffix in document.links.text above. You could then capture the list from the webviewer source. I did have a problem, though: The URL above works fine in Internet Explorer, but not in WebViewer. I welcome any input on that; I'm not clear on why some javascript injected into the URL works, and other javascript has issues? This would be a particularly useful methodology since it is easy to extract anything from the web page since JavaScript has access to the DOM. If you want the ability to search on xpaths, you might consider Webdriver (you can actually control it from Filemaker using Java and ScriptMaster). It can completely control firefox. http://code.google.com/p/webdriver/wiki/FirefoxDriver ; this allows xpath searches on the HTML, not just XML. Incidentally, you can actually run an MSXML parser within the webviewer using JavaScript, and use regular expressions on the webviewer's contents using javascript. Be sure to add back the domain since many paths are relative paths. Edited July 27, 2009 by Guest
Jim1 Posted July 27, 2009 Author Posted July 27, 2009 Thanks fseipel for the interesting post. I have given it a whirl and you are quite right that the JS does not execute directly in the FM WV. I'll have a play with things and see what I can do, to see if I can in some way get JS to retrieve the information that I need. Thanks, Jim.
fseipel Posted July 27, 2009 Posted July 27, 2009 Hi Jim, Attached is a solution, two scripts are included. The samples load http://www.ebay.com and report the list of links. One generates the list of links using Javascript access to the Document Object Model (DOM). The second generates a list of links using conventional scriptmaker parsing. The two results differ because I took a link to mean anything starting with href=" for the Filemaker link list; you can easily edit it to interpret what constitutes a link differently. The JS I posted earlier worked fine when posted into Firefox, but not IE. IE doesn't handle JS right! I found this JS did the trick in IE/webviewer: javascript:var i=0;var a=' '; while (i<=(document.links.length-1) ) { a = a + document.links[i] + ' '; i++; } document.content = a; By setting document.content = results, you don't run into the issues with webviewer thinking page hasn't loaded. The DOM solution is much shorter than Scriptmaker; only 2 lines of code; the rest is mostly to just wait for page to load. I couldn't get DOM to return results with Filemaker paragraph linebreaks, so I just use a substitute command to replace all with reverse P; then you can use FM function MiddleValues(link list, link_number,1) to extract individual links. It might be possible to have JS return FM linebreaks but I didn't explore it further. You can also do AES encryption, etc without a plugin using JS injection into webviewer; there are a lot of Javascript libraries available to perform a wide range of functions. JS_Injection_Example.zip
Jim1 Posted July 27, 2009 Author Posted July 27, 2009 Thank you so much for your reply. - That is exactly what I needed. I have tried the example and it works like a charm. Let me know if I can return the favor and help you with anything - I really appreciate it. Cheers, Jim.
Recommended Posts
This topic is 5609 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now