Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
202 views
in Technique[技术] by (71.8m points)

dom - How do I "select" a link using Javascript so enter visits it

I'm sure this is a basic question, but I just cannot find the right words to ask the almighty search-engines. I'm using the word "selected" in quotes because I don't know the right term for it. I'm sure if I did the question would be readily answered already.

When you press on most webpages, you are able to cycle through the links on the page such that when you press the browser visits the link in question. This is what a selected link looks like in Firefox:

A link in a browser that has a dashed border to signify it is selected

I want to be able to do this automatically on page load, such that immediately after load takes you to the link of my choosing, but any other shenanigans like inputting in an input field cancels this behavior. I've looked through the DOM browser and can see nothing jumping out differentiates "This is a link" from other links on this page.

question from:https://stackoverflow.com/questions/66062800/how-do-i-select-a-link-using-javascript-so-enter-visits-it

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It is called focus and you can have only one element focused. As soon as you click to an input your focus moves to it. That's why you can't have focused link while writing in an input at the same time.

Focus determines where keyboard events go in the page at any given moment.

Source & you can read more at: Introduction to Focus ?|? Web Fundamentals


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...