I have a requirement to show an Exit Popup on one of our processing pages. I am showing the exit popup by registering a client side javascript like
window.onbeforeunload = ShowExitPopUp();
The popup executes fine if you close the window, or try to type in a different URL. However the issue is that my processing page is also performing a "Response.Redirect" on the server side once the process completes. When response.redirect happens the exitpopup also shows up. Is there a way to have the exit popup not show up in that case?
this is the code below which i am using
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.Event.subscribe('comment.create',
function (response) {
window.location = "http://domain.com";
});
FB.Event.subscribe('comments.remove',
function (response) {
window.location = "http://domain.com";
});
};
(function() {
var e = document.createElement('script');
e.async = true;
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
//]]>
</script>
<script type="text/javascript">
var ShowExitPopup = true;
function ExitPage()
{
if (ShowExitPopup)
{
ShowExitPopup = false;
location.href = "http://www.YOURURL.com/destination";
return '****************************************\n\YOUR HEADLINE\n\n YOUR TEXT1 \n\n YOUR TEXT "\n\n | |\n | |\n V V\n 96+ v\n ********************************************************\n';
}
}
</script>
if (document.getElementById('<%=Panel.ClientID %>').style.display == "") {
$find("<%= Popup.ClientID %>").hide();
document.getElementById("<%= btncloseAcc.ClientID %>").click();
}
try this..........
Related
Hello i have this code which works for redirect back
Redirect Users leaving your site - Javascript back button hack
<?php
$javascript = <<<DOC
<script>
var ref = document.referrer;
var siteurl = "YOUR URL HERE";//if you have www, then use www. http://www.yoursite.com
if (ref.indexOf(siteurl)!= -1){
}
else{
(function(window, location) {
history.replaceState(null, document.title, location.pathname+"#!/auth");
history.pushState(null, document.title, location.pathname);
window.addEventListener("popstate", function() {
if(location.hash === "#!/auth") {
history.replaceState(null, document.title, location.pathname);
setTimeout(function(){
location.replace("http://www.blackhatworld.com/");
},0);
}
}, false);
}(window, location));
}
</script>
DOC;
echo $javascript;
?>
I want to add it a counter that will only redirect after 3 clicks on back.
How to do it?
try this javascript code :
<button id="button">Click Back 3 Times </button>
<script>
var counter = 0;
$("#button").click(function () {
counter++;
if (counter == 3) {
window.history.back();
}
});
</script>
This code also works but i need to add the counter
this code which works for redirect back Redirect Users leaving your site - Javascript back button hack:
<script>
// managage back button click (and backspace)
var count = 0; // needed for safari
window.onload = function () {
if (typeof history.pushState === "function") {
history.pushState("back", null, null);
window.onpopstate = function () {
history.pushState('back', null, null);
if(count == 1){window.location = 'http://google.co.il';}
};
}
}
setTimeout(function(){count = 1;},200);
</script>
Looking for a code to make redirect to page after clicking browser back button on the 3rd time... first 2 clicks should remain at the page
I want to make facebook like button.when i click like.undefined $ is appearing in console.it should echo 22 value default value on click.
function like_add(article_id) {
$.post('ajax/like_add.php', {article_id:article_id}, function(data){
if(data == 'success')
{
like_get(article_id);
}
else
{
alert(data);
}
});
}
function like_get(article_id) {
$.post('ajax/like_get.php',{article_id:article_id}, function(data){
$('#article_'+article_id+'_likes').text(data);
});
}
foreach($articles as $article){
echo '<li>',$article['article_title'],'</p><p><a class="like" href="#"
onclick="like_add(', $article['article_id'] ,');">Like</a>
<span id="article_', $article['article_id'] ,'_like">', $art
jQuery is not included in current page.
You can include it with this code:
<script src="https://code.jquery.com/jquery-2.2.1.min.js"></script>
Place it between <body> </body> before your code.
But also you can load it async way:
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = "https://code.jquery.com/jquery-2.2.1.min.js";
script.onreadystatechange = handler;
script.onload = handler;
head.appendChild(script);
function handler() { console.log("jQuery loaded!"); }
handler() will be called when jQuery will be loaded.
l am using this code
var exitPop = false;
var nonFire = false;
window.onbeforeunload = function () {
if(!exitPop){
exitPop=true;
return 'Wait! YOU ARE TODAYS WINNER!';
}
};
setInterval(function(){
if(exitPop && !nonFire){
nonFire = true;
window.location.href = 'http://google.com';
}
}, 200);
but its also execute on clicking any html redirect button on page.. i want it execute only if someone close browser and it should support all browsers.
i need to add this at only one link in my site how can id do? i mean i am using this code for redirect
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.Event.subscribe('comment.create',
function (response) {
window.location = "http://domain.com";
});
FB.Event.subscribe('comments.remove',
function (response) {
window.location = "http://domain.com";
});
};
(function() {
var e = document.createElement('script');
e.async = true;
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
//]]>
</script>
so i want exit function do not execute for this.. so how do integrate this
I haven't tested it but you should be able to attach a 'click' event to every link on the page, which should set a global variable such as
linkClicked = true;
You can then check that variable in the unload event
if (!linkClicked) // variable is false so they must not have clicked on a link
{
// Some annoying message here
}
Disclaimer: this is pretty much pseudo code, it's not a copy+paste solution.
window.onbeforeunload does not distinguish between links, back/forward buttons, exit buttons or anything else. If fires when you leave the page, regardless of how you leave the page.
I am using this code in php or html file for redirect
<script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"></script>
<script language="JavaScript">
var country= geoip_country_code();
if(country == "US" )
{
<!--
window.location = "http://google.com"
//-->
}
</script>
but i want to use a js file which do the same function but its extension should be .js
as http://domain.com/redirect.js so what would be the code?
This includes a script include function with a callback, so that the Maxmind client code won't run until the Maxmind library has been loaded.
loadScript("http://j.maxmind.com/app/geoip.js", function() {
var country = geoip_country_code();
if (country === "US") {
window.location = "http://google.com/";
}
});
function loadScript(url, callback) {
// adding the script tag to the head as suggested before
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
// then bind the event to the callback function
// there are several events for cross browser compatibility
script.onreadystatechange = callback;
script.onload = callback;
// fire the loading
head.appendChild(script);
}
Here's my code:
<script type="text/javascript">
(function() {
window.PinIt = window.PinIt || { loaded:false };
if (window.PinIt.loaded) return;
window.PinIt.loaded = true;
function async_load(){
var s = document.createElement("script");
s.type = "text/javascript";
s.async = true;
if (window.location.protocol == "https:")
s.src = "https://assets.pinterest.com/js/pinit.js";
else
s.src = "http://assets.pinterest.com/js/pinit.js";
var x = document.getElementsByTagName("script")[0];
x.parentNode.insertBefore(s, x);
}
if (window.attachEvent)
window.attachEvent("onload", async_load);
else
window.addEventListener("load", async_load, false);
})();
</script>
<!-- Customize and include for EACH button in the page -->
Pin It
The php successfully gathers all of the elements and when I click on the button, it pops up the modal window.
However, in the subsequent modal window, it does not pin to my board when I'm logged in.
The Script tag and link are both inside of a list item.
Any help would be appreciated.
Thanks,
Moises M.
From your description it sounds like the problem is that you are not url encoding the parameters, i.e. everything after the ?url=
I'm not sure if that's the only problem you'll run into with this, but it should fix the one you're currently hitting!