10 Replies Latest reply on Jan 5, 2010 2:30 AM by comment_1

    Fire Script when web viewer url changes

    Terminum

      Title

      Fire Script when web viewer url changes

      Post

      Is it possible to fire a script whenever the user navigates to a different page within the web viewer?

       

      Basically, whenever the web viewer url (source) changes I'd like to fire a script. I have tried using GetLayoutObjectAttribute ( "Viewer" , "source" ) in an unstored calculation field, but that doesn't seem to auto-update when the user navigates. If I can get that working, I think I'll be able to fire a script when the calculation field changes (using a plug-in), but that seems overly complicated. Plus I'm not sure that it will work. Is there an easier way to do this?<!--  POLLS  --><!--  FILES  --><!--  SIGNATURE  -->

       

      I'm using FileMaker 9 advanced on Mac os X and Windows XP.

        • 1. Re: Fire Script when web viewer url changes
          casey777
            

          What you want and need is the OnTimer function in Filemaker 10. I use it to reload a web site every 2.5 minutes whenever I am following that particular site. I then grab the contents and check for information I am seeking at which time when it changes or what I am looking for is available, my script runs a voice statement to alert me.

           

          Is that what you need? 

          • 2. Re: Fire Script when web viewer url changes
            Terminum
              

            Thanks for the reply, but I'm not sure that will work very well for my purposes. I'm not watching for changes on the website itself, I'm just trying to watch where and/or when the user is navigating. I want the script to run at least once for each page they visit. So I would need to run the OnTimer function every 1 or 2 seconds which seems like a lot of overhead.

             

            If it's possible, I could settle for firing the script whenever the user clicks (anything inside) the webviewer. I have tried making the web viewer into a button and executing the script whenever the webviewer is clicked, but then you can't navigate with the web viewer (like clicking links or buttons on the web page).

            • 3. Re: Fire Script when web viewer url changes
              casey777
                

              I misunderstood your question, but again in Filemaker 10 there are new script triggers which fire for various reasons including when the user modifies a field. I would believe the URL address is in a field and whenever that field is modified, the script would fire which could then provide the address and time for you. 

               

              The other problem for navigating within the web site is more of a challenge. You can capture the first portion of the source code every time it changes, but Filemaker cannot feed the web site address back to you whenever it changes.  

              • 4. Re: Fire Script when web viewer url changes
                Terminum
                  

                "You can capture the first portion of the source code every time it changes"

                 

                 

                Is there a way to do this without the OnTimer function? I may end up buying FM10 to try OnTimer, but I think it will be slow at the frequency I need it to run.

                 

                Is there a way to trigger a script when the web viewer has been clicked (without making the web viewer useless)? Then I could just call GetLayoutObjectAttribute ( "Viewer" , "source" ) whenever the web viewer has been clicked.

                • 5. Re: Fire Script when web viewer url changes
                  casey777
                    

                  In Filemaker 10 you would attach a script trigger, not an OnTimer script, to the web viewer so that every time it is modified a script could be executed. The triggers can run a script when the user enters a field, modifies it, saves it, leaves it, or for each keystroke the user enters.

                   

                  • 6. Re: Fire Script when web viewer url changes
                    Terminum
                      

                    Thanks for the continued support, however I've downloaded FM 10 and the script trigger does not seem to work like this for the web viewer, unfortunately.

                     

                    To setup the trigger, I tried right-clicking the web viewer > Select Script Triggers... then checked OnObjectModify and selected my script. The script never runs when you click in the web viewer or navigate to different pages within the web viewer. I confirmed that the script never runs with the Script Debugger open.

                     

                    So, I figured I would just set up an unstored calculation field to do  GetLayoutObjectAttribute ( "Viewer" ; "source" )  and then trigger the script when that field is modified. But the field doesn't update until you click it, which will be very unintuitive for the user. Is there anything else I can do? I would really prefer this route over a continuously running script.

                     

                    Thanks

                    • 7. Re: Fire Script when web viewer url changes
                      casey777
                        

                      You're right. The OnObjectModify script trigger does not work with changes inside the web viewer window. I tested adding a script trigger, but did not put it online. The Enter and Exit triggers do work.

                       

                      Here is something I did test. Add an OnTimer script to simply commit record every 15 or 30 seconds. All it will do is put the cursor outside the web viewer window. When the user enters the web viewer an OnObjectEnter trigger will fire if you activate one. That script can check if the left 100+ characters of the source content are the same as last time using variables. If it is, do nothing. If it is not, add a record with the new content to a related table.

                       

                      It still does not tell you exactly where the user has surfed unless there is enough information in the source content to identify it.

                       

                      Let me know if this works for you. 

                      • 8. Re: Fire Script when web viewer url changes
                        comment_1
                          

                        Terminum wrote:

                        Is there anything else I can do?


                        Perhaps you should explain what are you actually trying to achieve here: why should a script run whenever the URL changes, and what will the script do?


                        • 9. Re: Fire Script when web viewer url changes
                          Terminum
                            

                          Well, I gave it a try and had a few different problems with that approach. The biggest problem is that firing my script OnObjectEnter will prevent the first click in the web viewer from registering occassionally, so the user will actually have to double click links. The other problem is that if I'm typing something in the web viewer when the OnTimer commit record occurs then I'm kicked out of the web field and have to click in it again.

                           

                          Also, GetLayoutObjectAttribute ( "Viewer" ; "source" ) actually gives you the URL even though the parameter attribute is confusingly called 'source.' So if I can make the script fire correctly I will be able to get the the info I need.

                           

                          For now, I'm just using the OnTimer approach, firing off my script every 2 seconds which compares the current url to the last record one.This is a bit clunky though, but not as bad as a loop with pause/resume in FM 9. This approach is also problematic with pages that have a long load time, since the web viewer url does not update through GetLayoutObjectAttribute until the page finishes loading.

                           

                           

                           

                           

                           

                           


                          comment wrote:

                          Perhaps you should explain what are you actually trying to achieve here: why should a script run whenever the URL changes, and what will the script do?


                          The script just needs to record the new url and the time between navigations.

                           

                          I'm making a freeware program for A/B usability testing on websites. Google website optimizer does not track all of the history and it also requires you to add code to the website (usability analysts often do not have direct access). The Google tool is also very limited with regards to reporting options.

                           

                          • 10. Re: Fire Script when web viewer url changes
                            comment_1
                              

                            I am not sure Filemaker is the best tool for this - as you have discovered the links between the data layer and the web viewer are rather sketchy. Basically, it's no more than a browser stapled to the layout.

                            There are some plugins that improve on this, but I doubt there's a way to make Filemaker respond to user interacting with the "inner HTML" without rewriting the HTML code.

                             

                             


                            Terminum wrote:

                            if I'm typing something in the web viewer when the OnTimer commit record occurs then I'm kicked out of the web field and have to click in it again.


                            I don't see why you need to commit the record - I would try something like:



                            On entering web viewer:
                            1. Set a global variable to the current URL
                            2. Install OnTimer script

                             

                             

                            OnTimer script:
                            If [ $$url ≠ GetLayoutObjectAttribute ( "webviewer" ; "source" ) ]

                            # DO SOMETHING TO RECORD THE CHANGE

                            Set Variable [ $$url ; GetLayoutObjectAttribute ( "webviewer" ; "source" ) ]
                            End If



                            On exiting web viewer:
                            Uninstall OnTimer script