Is it possible to remember scrollbar position after form submit and returning back to the home page?
Here is my form:
<form method="post" action="{{Route('sites.liking')}}">
<input name="_token" value="{{csrf_token()}}" type="hidden">
<input type="hidden" value="{{$meme->likes}}" name="likes">
<input type="hidden" value="{{$meme->id}}" name="likeid">
<input type="hidden" value="{{Auth::user()->name}}" name="sendeduser">
<button class="linking">+ {{$meme->likes}}</button>
</form>
Routing:
Route::post('/', ['uses' => 'LikingComments@liking', 'as' => 'sites.liking']);
Controller function:
public function liking(Request $request) {
//Function guts
return redirect('/')->with('status', $id);
}
I've tried several scripts but it always scrolls to the top of the page.
Is there a some way to go back to the same place of the page ?
Okay I've solved up that problem by adding an id to an element, new routing and changing main function.
<div id="{{$meme->id}}">
<form method="post" action="{{Route('sites.liking')}}">
<input name="_token" value="{{csrf_token()}}" type="hidden">
<input type="hidden" value="{{$meme->likes}}" name="likes">
<input type="hidden" value="{{$meme->id}}" name="likeid">
<input type="hidden" value="{{Auth::user()->name}}" name="sendeduser">
<button class="linking">+ {{$meme->likes}}</button>
</form>
</div>
Changed function:
public function liking(Request $request)
{
//Function guts
return redirect()->action('LikingComments@indexliking', ['id' => $id])->with('status', $id);
}
Routing:
Route::get('/#{id}' , ['uses' => 'LikingComments@indexliking', 'as' => 'indexliking']);
It don't work perfectly but it's fine for me. Thank you for your answers especially @kerbholz
You can use localStorage or sessionStorage to save current scroll position (scrollTop). and then assign it to scrollTop when you reload that previous page.