On Codeigniter I have a code
HTML
//ROOTPATH is the constant Path and $recordId is coming from a loop.
Delete
Javascript
windowRedirect(url,msg)
{
if(confirm(msg))
{
window.location.href = url;
}
else
{
return false;
}
}
I have written a simple javascript which will redirect url if user click on OK button but I am getting weird problem on Google chrome where this code is working perfectly on Mozila Firefox, IE 8/9 and Applae Safari. Can any one tell me how can I solve this Google Chrome Problem.
Though I have a doubt this script is probably not working because of '#' on the href field but I am not sure.
Here is an working example:
<html>
</head>
<script>
function window_redirect(url,msg)
{
if(confirm(msg))
{
window.location = url;
}
else
{
return false;
}
}
</script>
</head>
<body>
<a onclick="window_redirect('http://www.google.com','Are you sure you want to Delete');" href="#" >Delete</a>
</body>
</html>
You forgot to call state 'function' before function, also if you put onclick on a element (link) always put it before href="#" some browsers will not call onclick if that is not the case.
Related
I can not get this jQuery to work on page load? I use fancybox 3.
<script>
function openFancybox() {
setTimeout( function() {
$('[data-fancybox data-src="#newsletterFancy"]').trigger('click');
}, 20000);
}
$(document).ready(function() {
var visited = $.cookie('visited');
if (visited == 'yes') {
return false;
} else {
openFancybox();
}
$.cookie('visited', 'yes', { expires: 7 });
$('[data-fancybox data-src="#newsletterFancy"]').fancybox();
});
</script>
I have also added this to my body tag: <body OnLoad="openFancybox()" class="body">
I basically have my pop up in a included file called newsletter.php. The link in my sidebar works fine when i click that. But i want to make it pop up and open on page load with a delay and also for it to set a cookie.
I have also included the cookie js as well:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
This is the line I use in my sidebar link for it to open when you click it:
<a class="buttons" data-fancybox data-src="#newsletterFancy" href="javascript:;">Newsletter Subscribe</a>
Thanks
You are simply not using valid selector. Replace
$('[data-fancybox data-src="#newsletterFancy"]')
with, for example:
$('[data-src="#newsletterFancy"]')
I have a pagination that I did only with php, but now Im trying to do my pagination using ajax and some fade effects.
I have this link in my index.php to pass my BASE, that is my htttp://localhost/project url to jQuery:
<link rel="nofollow" title="base" href="<?php echo BASE; ?>" />
Then I have my jQuery function that works when I click in my pagination link.:
$(function(){
base = $('link[title="base"]').attr('href');
urlaction = base+'/actions';
alert(urlaction);
$('#body-content').on('click','.paginator a',function(){
if($(this).hasClass('active')){
return false;
}else{
$('#body-content .paginator span').css({color:'#FFF','border-color':'#fff'});
$('#body-content .paginator a').removeClass('active');
$(this).addClass('atv');
var url = $(this).attr('href');
var data = url.lastIndexOf('/') + 1;
var data = url.substr(data);
$('#body-content .news').fadeTo(500,'0.2');
$.post(urlaction,{action:'article_pagination',page:data},function(pagination){
alert(pagination);
$('html, body').delay(500).animate({scrollTop:$('h2').offset().top},500);
window.setTimeout(function(){
$('#body-content').html(pagination);
$('#body-content .news').fadeTo(500,'1');
},600);
});
}
return false;
});
});
If I alert my alert(urlaction) I get my localhost/project/actions, so its correct it is my url to my actions.php file.
But when I do my alert(pagination); I get my alert with all code that I have in my index.php inside alert box, so it seems that is not getting the correct path to my actions.php file. But The path is correct...
Do you see what can be wrong here??
My alert appears like:
<!DOCTYPE html...>
<html xlmlns>
....
and all my index.php content
I am guessing you are missing the $ before BASE and are seeing an error page alerted back to you with that info.
I am working on a Wordpress site using the Vanilla forum plugin. I found HTML code below after I checked firebug:
<ul>
<li>Diets That Work</li>
<li>Heart Disease Support</li>
</ul>
I have only have a problem in Safari browser; when I click either of the first two links, it goes to http://knowmoretv.com/discussions-4/ but if use any other browser it goes to http://knowmoretv.com/discussions-4/#/discussion/73/diets-that-work (or heart-disease-support, as I'd expect).
Should i use jQuery code redirect # to /# in safari browser?
i have fixed that problem by jQuery for Safari browser
<script type="text/javascript">
$(document).ready(function(){
$.browser.safari = $.browser.webkit && !window.chrome;
if ($.browser.safari) {
$("a").click(function(event){
event.preventDefault();
var urlval = $(this).attr('href').split('#');
var urlvals = urlval[0]+'/#'+urlval[1];
var pathname = window.location.pathname;
if(pathname == '/discussions-4/')
{
window.location.assign(urlvals);
window.location.reload(true);
}
else{
window.location.assign(urlvals);
}
});
}
});
</script>
I have a small problem. I am trying to submit a form to
http://www.fikeandfike.com/propertytax/Grundy/Inquiry.aspx
but it cannot be directly navigate even in browser(i really don't have a clue why?)
to go to above link it is mandatory to click "Parcel enquiry" on
http://www.fikeandfike.com/propertytax/Grundy/MainMenu.aspx?c=32
so i want to click and follow the "parcel enquiry" link using a php script.
if i directly access the former link using cURL i get "Object reference not set to an instance of an object." error
please guide me on how to click and follow the link
To get the same result using PHP you will need to have the Javascript function that is called on clicking 'Parcel Inquiry' in your PHP script, to mimic the result:
HTML for the link in your PHP script:
<a id="ctl00_Main_lnkParcelInquiry" style="color:Blue;" href="javascript:__doPostBack('ctl00$Main$lnkParcelInquiry','')">Parcel Inquiry</a>
JS to define the __doPostBack function and form in your PHP script:
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['aspnetForm'];
if (!theForm) {
theForm = document.aspnetForm;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
//]]>
</script>
<script src="/PropertyTax/Grundy/WebResource.axd?d=k82Y5NDDJDDbxvQs15CYbKKGrXzg8maOqY0bqltbogQI3NDmBuf75gWfcLjILBbAmbWOYgfVPqLiO6Kf2KileNBCke01&t=634622168376055000" type="text/javascript"></script>
And so you will also need that form, <form name="aspnetForm" action="http://www.fikeandfike.com/propertytax/Grundy/Inquiry.aspx">, to exist in your script.
It's just a matter of doing it the same way; so copy the code and the functions and you should get the same results.
hey guys I'm having a problem with an upload form I've made. It works in Firefox and IE but it wont work with Safari and Chrome so I assume it's a webkit problem.
First I run the php form and change the target to an iframe. Then once it's finished uploading I get PHP to echo a div iwth a statement true/false back into the iframe.
The problem i'm having is that PHP isn't echoing the statement into the iframe.
here's the code i've got:
in the php:
//do all the appropriate checks etc and if it's uploaded do the following
if ($success == true)
{
echo '<div id="result">success</div>';
} else {
echo '<div id="result">error</div>';
}
then in my javascript I do a few checks to see if the forms filled out etc and then if all is well I call submit() first and then I call iframeCheck()
function submit()
{
//change the target of the upload form to upload to the iframe.
$('#contactForm').attr('target','uploadIframe');
//submit the iframe
$('#contactForm').submit();
//fade in the sending message
$('#sendingMessage').fadeIn(200);
}
function iframeCheck()
{
//get the contents of iframe
var elem = $('#uploadIframe').contents().find('div#result');
var result = elem.html();
//if there's nothing in it, upload hasn't finished...
if ( elem.length <= 0)
{
//check it again in 2"
clearTimeout(timer);
var timer = setTimeout(iframeCheck, 2000);
} else if (result =='success'){
//if it contains a success message, display the success message
$('#sendingMessage').fadeOut(200);
$('#successMessage').fadeIn(500);
inputButton.removeAttr('disabled');
} else {
if (result == 'error')
{
//otherwise display the error message
$('#sendingMessage').fadeOut(200);
$('#failureMessage').fadeIn(500);
inputButton.removeAttr('disabled');
}
}
}
It works fine in ff and IE but as i said chrome and safari wont echo into the iframe.
Thanks for your help folks!
Is the iFrame URL the same domain as the general homepage? Perhaps it has something todo with cross domain policy.
Thanks heaps for your guys help. John it was a problem with my javascript. I was disabling the send button as soon as it was clicked. This worked fine except that webkit didn't like it so what I had to do was add onsubmit="document.getElementById('submitButton').disabled=true;" and that works fine now.
Cheers