[英]Keep Page Scroll on parent page when closing the Dialog Child Page
I'm currently working on a new dialog box and that is opened by a link in the page and once the Dialog box is closed, it refreshes the Parent page but my question is how can i stay the Parent current scroll on page refresh 我正在处理一个新的对话框,它是通过页面中的链接打开的,一旦对话框关闭,它会刷新父页面,但我的问题是如何在页面刷新时保持父当前滚动
Here is the dialog Close code: 这是对话框关闭代码:
$("#dialogStatus").dialog({
autoOpen: false,
autoResize: true,
resizable: false,
width: 450,
height: 400,
modal: true,
position: ['center', 40],
close: function (event, ui) {
var sss = $("#Id").val();
var hNotif = $("#hiddenNotification").val();
var ddlvalue = $('#NewFilterBy option:selected').val();
var ddlStat = $('#StatusId option:selected').val();
var url = window.location.href;
var newUrl = updateQueryStringParameter(url, "Id", sss, "ddlFilter", ddlvalue, "statusFilter", ddlStat);
window.location = newUrl;
}
});
What happens here now is when I close it, it refreshes and the parent stay at scroll stays at Top of the page 现在这里发生的事情就是当我关闭它时,它会刷新并且父级保持滚动停留在页面顶部
Edit: Tried adding the document.location.reload()
but it loses the parameter once added 编辑:尝试添加
document.location.reload()
但它一旦添加就丢失参数
You can try to put a parameter 'scrollPosition' in your URL String and when your document is loaded scroll down to the position. 您可以尝试在URL字符串中放置参数“scrollPosition”,并在文档加载时向下滚动到该位置。
$(document).ready(function(){
//The function that scroll down
var positionToScroll ; //You set here your variable from your server variable scrollPosition
$(window).scrollTop(positionToScrol);
$("#dialogStatus").dialog({
autoOpen: false,
autoResize: true,
resizable: false,
width: 450,
height: 400,
modal: true,
position: ['center', 40],
close: function (event, ui) {
var sss = $("#Id").val();
var hNotif = $("#hiddenNotification").val();
var ddlvalue = $('#NewFilterBy option:selected').val();
var ddlStat = $('#StatusId option:selected').val();
var url = window.location.href;
var currentScrollPosition = $(window).scrollTop(); // The position of the scroll bar
var newUrl = updateQueryStringParameter(url, "Id", sss, "ddlFilter", ddlvalue, "statusFilter", ddlStat,"scrollPosition",currentScrollPosition );
window.location = newUrl;
}
});
});
Edit: If you can't SET your JS variable 'positionToScroll' from your server you can use this 编辑:如果你不能从你的服务器设置你的JS变量'positionToScroll'你可以使用它
var getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = window.location.search.substring(1),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
}
}
};
var positionToScroll = getUrlParameter('scrollPosition');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.