Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open an html page to an anchor on Mac OS from command line

I would like to open a web page to a to specific anchor.

eg:

open index.html#intro

When I try this, I can get error saying

index.htm.l#intro does not exist

like image 923
Sheldon Warkentin Avatar asked Apr 25 '13 19:04

Sheldon Warkentin


People also ask

How do I open an HTML File on a Mac?

View an HTML document In the TextEdit app on your Mac, choose File > Open, then select the document. Click Options at the bottom of the TextEdit dialogue, then select “Ignore rich text commands”. Click Open.

How do I link to an anchor in HTML?

In the text editor, click SOURCE. Navigate to where you want to insert an anchor. In the HTML code, insert the anchor using the format id=“anchor_name” within the <p> tag. Note: IDs on a page must be unique, and can't be re-used for other anchors.

How do I open the web terminal on a Mac?

On your Mac, do one of the following: Click the Launchpad icon in the Dock, type Terminal in the search field, then click Terminal. In the Finder , open the /Applications/Utilities folder, then double-click Terminal.


2 Answers

It won't open because it thinks you're typing the file name index.htm.l#intro. As far as I can tell you can't open a page from the command line to an anchor.

As a workaround you could include javascript to jump to the specified anchor using the onLoad function or Jquery document.ready.

like image 134
Jordan Avatar answered Sep 30 '22 03:09

Jordan


You could also use AppleScript command line (in Terminal):

osascript -e 'tell application "Safari" to open location "file://{full_path}/index.html#intro"'

in which {full_path} is the absolute path to the file.

like image 31
vvasch Avatar answered Sep 30 '22 01:09

vvasch