How to redirect to a specific section of a page in html

Please help me with the code to redirect to a specific section of the page.

I did a redirect to the landing page, but I want to redirect to a specific <div> page.

Thanks in advance

+7
html
source share
6 answers

You can do this in two ways.

1) [via Javascript (+ jQuery)]

 <a href="#" id="home">home</a> $('#home').click(function(){ $(document).scrollTop(100) // any value you need }); 

2) [via pure HTML]

 <a href="#home_section">home</a> <section id="home_section"></section> 
+14
source share

You need to add the id attribute to this section of the page that you want to display and pass the id name at the end of the URL using the hash ( # ) symbol. For example, you want to redirect the user to a div using id='test'

 <div id="test">your section content</div> 

Then you should use this URL structure:

 http://example.com/your_page.php?some_param=1#test 
+2
source share
 <div id="go1"> <!-- content --> </div> <div id="go2"> <!-- content --> </div> <div id="go3"> <!-- content --> </div> ... 

Just add the URL id as shown below and you're done!

 news.html#go1 news.html#go2 news.html#go3 
+2
source share

Basically, you use anchor tags in HTML to do your job. You are probably familiar with them, like:

 <a href = " "> </a> 

As an HTML convention, when defining a section, you can provide each section with an identifier for identifiers:

 <section id= "blahblah" ></section> 

And you can redirect to the section by simply specifying them in the anchor tags:

 <a href = "#blahblah"> </a> 
+1
source share

You can link the html code with css.

In c #

 Response.Redirect("http://www.example.com/index.aspx#id_in_css"); 
0
source share

Give this section an id (say: section1 ) and then the redirect URL will be http://www.sample.com/page#section1 .

Note : # and the keyword, that is, the identifier of the section into which you want to scroll your browser.

Read more about Fragment ID here

0
source share

All Articles