Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect to another page and specific div on button click in mvc

Tags:

html

jquery

c#

css

I have one page called Page1 which have a button.

<button onclick="redirecttodivofotherpage(); "></button>

The other Page2 have 3 Div

<div id="div1"></div>
<div id="div2"></div>
<div id="div3"></div>

I want to redirect to div3 on button click of Page1 button.
How to do it with controller or jquery.

like image 921
Saurabh Solanki Avatar asked Dec 05 '22 16:12

Saurabh Solanki


2 Answers

You could try something like this:

<button class="js-btn"></button>

$(function(){
    $(".js-btn").on("click",function(){
        window.location = "..../#div3";
    });
})

The string "..../#div3" represent the relative url of your page and at the end has a #div3. This way, using window.location, you would be redirected to the page you want and using #div3 to the section you want.

like image 57
Christos Avatar answered Jan 02 '23 04:01

Christos


This can be done with cookies. Setting a cookie with id you want to scroll, and then, when the new page is loaded, read the cookie and scroll to defined id. I used the very popular plugin jquery-cookie.

Check this sample solution Note: Click on Events to nav to the other page.

**http://plnkr.co/edit/hBJj69nP6kvrEuoCVw3k?p=preview**
like image 21
Keshan Nageswaran Avatar answered Jan 02 '23 03:01

Keshan Nageswaran