Using webbrowser activex object, cannot get bookmarks within page to work if bookmark has space in the name

Posted on 2006-04-22
Last Modified: 2008-03-17

I am using the MS Web Browser activex object in a form to display context sensitive help.

If I pass a URL using Navigate such as "c:\page.htm#bookmark", it works fine.  However if there is space in the bookmark name ("c:\page.htm#book mark") it doesn't, although the name is valid and exists in the page and works if you type the url direct into an IE address bar.  All it does is display the page starting at the top.

I've tried replacing the space with %20, but still no joy.

Using Windows 2000 Server, Access 2000, IE6

Any thoughts?
Question by:rgke001
    LVL 42

    Expert Comment

    Just a hunch, try putting bookmark path in double-quotes.  If already in quotes then, try triple-double, i.e.
    """c:\page.htm#book mark"""

    LVL 44

    Expert Comment


    LVL 58

    Accepted Solution


    True bug. This seems to be caused by a defective internal threading mechanism. An anchor containing a space is recognized only once the HTML containing has been loaded (that is true for all anchors) but the URL parser does not wait for the load to complete. It does if there is no space...
    But it could be anything else, and this is not open source ;)

    I couldn't find a good fix, so here is a workaround:

        strURL = "file:///c:/page.htm#book mark"
        With Me.acxBrowser.Object

            ' normal navigation (creates the Document object)
            .Navigate strURL
            ' YABOMS: doesn't find bookmarks with spaces!
            ' need a workaround...
            ' wait for up to 5 seconds while browser is busy
            sngStamp = Timer()
            Do   ' at least one DoEvents is needed for this to work
            Loop While .Busy _
            And sngStamp <= Timer() And Timer() < sngStamp + 5

            ' reset document's URL now that the full page is loaded
            .Document.URL = strURL

        End With

    Good luck!

    Author Comment

    Fantastic - how do you figure out all this stuff??
    LVL 58

    Expert Comment

    Frankly? I didn't believe you and tried it for myself ;)

    Then I was hooked and tried other navigations methods, until one worked. The "explanation" is pure guesswork, but this _is_ a bug, no doubt about it.

    Anyway, I'm glad you like this workaround. happy automated browsing!

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
    Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
    Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
    In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now