Reputation: 7707
I have got a link with the click event in my JQuery, something like below:
$('#TopLoginLink').click(function()
{
//Here I want the current page should be reloaded with "https" and after the page is loaded then it will automatically call my function MyDialogPopup(). Something like below:
var myCurrentPage = window.location.href.replace('#','');
var reloadURL;
if (https!=' ')
{
reloadURL = myCurrentPage.replace('#','').replace("http",https);
window.location.href = reloadURL;
MyDialogPopup();
}
});
The above code is reloading my page perfectly, however my problem is that my function is also called immediatley, but I want my function should be called only when my page is loaded with "https" completely.
Please suggest! how can I achieve this
Upvotes: 3
Views: 6118
Reputation: 11658
You should define some flag. For example put something in cookies or append to url. Then, in your javascript define ready
handler then will be called when page is loaded:
$(document).ready(function() {
if (checkFlag()){
MyDialogPopup();
clearFlag();
}
});
Your handler will be looking like this:
if (https!=' ')
{
reloadURL = myCurrentPage.replace('#','').replace("http",https);
setFlag();
window.location.href = reloadURL;
}
If your stick with cookies, you can use jquery.cookie plugin. Here is code for setFlag
, checkFlag
, clearFlag
:
function setFlag(){
$.cookie('show_dlg', 'true');
}
function clearFlag(){
$.cookie('show_dlg', null);
}
function checkFlag(){
return $.cookie('show_dlg') == 'true';
}
Upvotes: 2
Reputation: 10771
I believe this code executes once the page is loaded:
$(document).ready(function() {}
Upvotes: 0
Reputation: 1039508
You could put the MyDialogPopup
method call in $(document).ready
and not after modifying the window.location.href
:
$(function() {
if (do some checks on the url if we need to call the method) {
MyDialogPopup();
}
});
Upvotes: 0