qlmanage and html files: How can I jump to a location/anchor in a html file

Discussion in 'Mac Programming' started by gregor.hoch, Apr 15, 2012.

  1. macrumors member

    Joined:
    Apr 5, 2011
    #1
    I am trying to use qlmanage, a terminal command to perform Quick Look actions, to open a html file and jump to a specific location in the file (anchor). In the browser, I would just use file:///[LOCATION]/test.html#jump but that does not work with qlmanage. Below is an example that works with qlmanage and some attempts to jump to the anchor, which are not working.

    Note that Quick Look itself can jump to anchors in html files. When I open links from emails with anchors, quick look jumps to the correct location. Hovering over the link in an email shows this:
    'x-apple-ql-file:///[LOCATION]/test.html?/[LOCATION]/#jump

    Thanks!



    Works

    Code:
    /usr/bin/qlmanage -p '~/Desktop/test.html'
    Doesn't work

    Code:
    /usr/bin/qlmanage -p '~/Desktop/test.html#jump'
    /usr/bin/qlmanage -p 'file:///[LOCATION]/test.html#jump'
    
    Example HTML File

    Code:
            <head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="chrome=1"></head>
            
            <body>
            	<h1>Heading</h1>
            	<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
            	<p id="jump">
            		jump here
            		<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
            	<p>
        
        </body>
     
  2. macrumors regular

    Joined:
    Aug 5, 2007
    #2
    To jump to an anchor in an HTML page you do not give an element an id with the anchor name. Instead you use
    Code:
    <a name="jump">Jump here</a>
    Then you can use the URL
    Code:
    http://www.example.com/page.html#jump
    http://www.w3schools.com/html/html_links.asp
     
  3. thread starter macrumors member

    Joined:
    Apr 5, 2011
    #3
  4. chown33, Apr 16, 2012
    Last edited: Apr 16, 2012

    macrumors 603

    Joined:
    Aug 9, 2009
    #4
    Your non-working examples don't follow the same syntax as your email example. I've hilited the difference in red.

    I'm pointing this out for logical reasons, not because it works.


    When I try the first example command, I get multiple warnings and errors output. They all say there's no such file. This is after creating the test.html file on my Desktop, and after running the posted command that works. (As run on Snow Leopard.)

    Did you get any error messages? What did they say?


    Your example HTML file is also missing a <!DOCTYPE>, and the <html> tags. My test file had them.
     
  5. thread starter macrumors member

    Joined:
    Apr 5, 2011
    #5
    I am getting the same error message. Something like file not found.

    I guess I double pasted with the highlighted syntax example. Sorry for that. But I never got 'x-apple-ql-file' to work with qlmanage anyway.

    Thanks for your trials!
     
  6. macrumors 603

    Joined:
    Aug 9, 2009
    #6
    When posting questions, it's always a good idea to mention error messages. It's an even better idea to post the actual text of the complete error message.
    http://www.mikeash.com/getting_answers.html


    I'll also point out that qlmanage isn't really "a terminal command to perform Quick Look actions". It's a debugging and management tool. That's what it says in its man page. It should also be obvious because the QL window that shows the preview has the word "DEBUG" in its title.

    I mention this because it's quite possible you'll have to write a command-line tool in order to get what you want. To that end, you should probably start by reading the Quick Look Programming Guide.

    Just because a tool can be used for X doesn't mean it was designed for X, nor that it can accomplish all possible variations on X.
     

Share This Page