The login page on my DNN website doesn't submit when you hit enter. After poking around in the /DesktopModules/AuthenticationServices/DNN/Login.ascx file, I found out that the culprit is that <%#ModuleId%> isn't returning the module ID.
Here is how it's used:
<script type="text/javascript">
/*globals jQuery, window, Sys */
(function ($, Sys) {
function setUpLogin() {
var actionLinks = $("a#dnn_ctr<%#ModuleId%>_Login_Login_DNN_cmdLogin");
actionLinks.click(function () {
if ($(this).hasClass("dnnDisabledAction")) {
return false;
}
actionLinks.addClass("dnnDisabledAction");
});
}
$(document).ready(function () {
$('.dnnLoginService').on('keydown', function (e) {
if (e.keyCode === 13) {
var $loginButton = $('#dnn_ctr<%#ModuleId%>_Login_Login_DNN_cmdLogin');
if ($loginButton.hasClass("dnnDisabledAction")) {
return false;
}
$loginButton.addClass("dnnDisabledAction");
eval($loginButton.attr('href'));
e.preventDefault();
return false;
}
});
setUpLogin();
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function () {
setUpLogin();
});
});
}(jQuery, window.Sys));
</script>
The login button ends up with an id of dnn_ctr3927_Login_Login_DNN_cmdLogin but the final jQuery spits out dnn_ctr_Login_Login_DNN_cmdLogin causing the code above not to work right.
How can I get the correct Module ID without hard-coding it?
I think it's a bug. I replaced #ModuleId by =ModuleId and it seem's to work.
i suggest you to try this modification in the /DesktopModules/AuthenticationServices/DNN/Login.ascx file.
Related
Using Tampermonkey to change the behavior of a website. Have some problems with a website with the following code:
<script language="JavaScript">
if (typeof jQuery != 'undefined') {
jQuery(window).load(function() {
window.setTimeout(function() {
window.location.replace(window.location.href);
}, 180E3);
});
}
</script>
How does one remove/prevent it reloading the page?
Without messing that much with jQuery, if your script runs before that piece of code you can do the following:
jQuery.fn.load = function() {
console.log("Tried to reload the page!")
}
// Then the following, outputs 'Tried to reload the page!' and does nothing else
jQuery(window).load(function() {
// code
})
If you still need the load function afterwards you could do the following:
var oldLoad = jQuery.fn.load
var undesiredCallback = "function() {
window.setTimeout(function() {
window.location.replace(window.location.href);
}, 180E3);
}"
jQuery.fn.load = function(callback) {
if(callback.toString() !== undesiredCallback) {
oldLoad(callback);
}
}
But it's browser dependent and very unreliable
Another way would be adding a onbeforeunload event, but that would pop a prompt on your tab:
window.onbeforeunload = function() {
return "Stay here please";
}
You can also override setTimeout functionallity.
var oldSetTimeout = window.setTimeout;
window.setTimeout = function(func,interval){
if(typeof func === "function" && func.toString().indexOf('window.location.replace(window.location.href)') > -1){
/*do nothing*/
}else{
oldSetTimeout(func,interval)
}
}
I've come across a nasty website that managed to refresh the page every time I tried to close the tab. Basically you couldn't close that page. I got around it by disabling javascript on that page.
How do they do it?
I've tried location.replace inside onbeforeunload and it doesn't work:
window.onbeforeunload = function(e) {
window.location.replace(window.location.href);
};
Here is the source of the page in question, where I don't get how they do it:
<script type="text/javascript">
function c(b)
{
document.write(b);
}
function wrapped3(d)
{
return d.replace(/(.)(.)/g, '%$1$2');
}
function wrapped(b)
{
var tmp = window['decodeURI' + 'Component'];
return tmp(wrapped3(b))
}
function show_page(a)
{
c(wrapped(a)
.split('{{addr}}').join('//ip')
.split('{{country}}').join('Great Britain')
.split('{{region}}').join('London, City of')
.split('{{city}}').join('London')
.split('{{ltude}}').join('//latitude')
.split('{{referrer}}').join('//url here')
);
}
show_page('//long string here');
</script>
window.onbeforeunload is the correct solution, here is an example:
var popit = true;
window.onbeforeunload = function() {
if(popit == true) {
popit = false;
return "Are you sure you want to leave?";
}
}
http://jsfiddle.net/SQAmG/3/
I am using native.history.js to put a customised URL in the back button.
The script works fine. Now the issue is I want to make a page redirect when the refresh button is clicked; so i modified the script like this:
<script>
var back = 0;
$(window).bind('beforeunload', function () {
if (confirm('Want to continue?')) {
if (back == 1) {
alert('back');
//window.location.href = "<?=$$last_offer?>";
} else {
alert('refresh');
//window.location.href = "<?=$actual_link;?>";
}
} else {
// Do nothing!
}
});
window.onpageshow = function (e) {
if (e.persisted) {
location.reload();
}
};
window.onpopstate = function (event) {
if (document.location.toString().indexOf("redir=1") > 0) {
back = 1;
window.location.href = "<?=$$last_offer?>";
}
};
</script>
Issue is, the beforeunload function seems not working.
What is the problem I can't fin?.
If I am clicking the back button, the page is taking to the desired page, so it works fine.
All I want is that, somehow the page refresh must work as I anticipated.
Try use
$(window).on('beforeunload', function(){
return 'Are you sure you want to leave?';
});
Instead of bind, use on, i dont know what jquery version you use, but i will suggest "on".
Works fine here:
link
on jquery version 2.x(edge)
i have below code to invalidate session on window unload
window.onbeforeunload = function(event) {
if (typeof event == 'undefined') {
event = window.event;
}
if (event) {
console.log("closing the browser, invalidating the session");
$.ajax({
url : "/inValidateOnBrowserClose.html",
type : "get",
cache : false,
}).done(function(data) {
console.log(" invalidated session on browser close event");
});
}
return true;
};
$(function() {
$("a").click(function() {
window.onbeforeunload = null;
});
$("button").click(function() {
window.onbeforeunload = null;
});
});
all working fine, but i have a page where i have a dynamically created buttons.
<span class="myButton"><a href="javascript:submitForm" >Update </a></span>
when i click above anchor (button) my window unload event is getting called (in my case it should not get called), i am surprised why $("a").click(function()) is not called in first place, i am trying to fix this but no luck. Thanks for your answers
You need to use delegate here like below for binding click events to dynamically generated elements :
$(function() {
$(document).delegate("a","click",function() {
window.onbeforeunload = null;
});
$(document).delegate("button","click",function() {
window.onbeforeunload = null;
});
});
And this works for already existing elements, so no need to write separate click binding.
For firefox user delegate function may not work so they can use on. please see below code
$(function() {
$("a").on("click",function() {
window.onbeforeunload = null;
});
$("button").on("click",function() {
window.onbeforeunload = null;
});
});
Stackoverflow Issue
I am using sammy.js plugin in my single page application. The plugin is not working, whenever user tries to navigate in the page it is showing the following error on console :
[Tue Dec 04 2012 17:48:13 GMT+0530 (India Standard Time)] #main 404 Not Found get /page_home
Error
arguments: undefined
get stack: function () { [native code] }
message: "404 Not Found get /page_home "
set stack: function () { [native code] }
type: undefined
__proto__: d
What is this issue and how can it be fixed ?
EDIT
Sammy configuration code:
var app = $.sammy('#main', function () {
this.get('#/:name', function () {
var id = this.params['name'];
$.trim(id);
var flag = true;
if ($("#main").hasClass("presentation")) {
$.each(slides, function (i, v) {
if ($(v).attr("class") == id) {
ScanNavigationD(id);
flag = false;
return false;
}
});
if (flag) {
ScanNavigationD($(slides[0]).attr("class"));
}
}
else if ($("#main").hasClass("printdoc") || typeof $("#main").attr("class") == "undefined") {
$.each(Pages, function (i, v) {
if ($(v).attr("class") == id) {
ScanNavigationD(id);
flag = false;
return false;
}
});
if (flag) {
ScanNavigationD($(Pages[0]).attr("class"));
}
}
});
});
$(function () {
app.run();
});
#tom-rider the problem is the app.run called without argument.
The sammy app.run function accept a start_url argument to set (via the _setLocation method) the app current location before call _checkLocation method to check if url is changed...
So try to change
app.run();
with
app.run('#/');
this work for me.
Follow this fiddle for a working demo and look at the console: no error!
will this simple code work?
var app = $.sammy('#main', function () {
this.get('#/:name', function () {
alert(this.params['name']);
});
});
$(function () {
app.run();
});
if this small code alerts 'page_home' there is something wrong with your script inside:
then you should be able to answer these questions: where is the ScanNavigationD-Function? where are the "slides"/"Pages" - arrays defined?
EDIT:
ok, i did another test at my computer. thats what i did:
created a html-document
included first jQuery then sammy.js
<script src="http://code.jquery.com/jquery-1.8.3.min.js" type="text/javascript">
<script src="sammy.js" type="text/javascript">
i filled the vars and functions i asked for with dummy-content:
<script>
var ScanNavigationD = function() {},
slides = ['slide1', 'slide2'],
Pages = ['page1', 'page2'];
<script>
then i copy pasted your code into my html-document.
<script>
//your code
<script>
then i created the div-main container:
everything worked. the last thing i see you are doing wrong is, that you are just on your local filesystem.
sammy.js seems to need a webserver to run! at least localhost!
file://...
WILL NOT WORK
Seems like you are sending in page_home as a parameter when running the script which resolves to a 404 not found error. Try look for 'page_home' throughout your files, recursively to find where this is coming from.