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
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With