Jquery - Popupwindow Not Working on FIrst Click - javascript

I am trying to use a popupwindow function. The problem is, it works only on the second click and so on. If I refresh the page, it will not work on first click. Why does it happen? Below are my codes,
$(document).ready(function(){
function popup(e){
e.preventDefault();
$(".popupwindow").popupwindow();
}
$('.popupwindow').on("click", popup);
});
Link that use the function:
Click Here

Related

After second triggered function button inside execute code twice

I make a game and I have problem that I cant solve.
I have function and inside I have buttons with .click(). After I execute function for second time buttons clicks execute code twice for example I post here some simple code with same problem.
When I click 1st button alert is triggered once. When I click 2nd and then 1st button alert is triggered twice. I want trigger alert just once. Buttons must stay in function. Sorry for bad English.
Also jsfiddle here https://jsfiddle.net/o2gxgz9r/25237/
function testf() {
$("#1").click(function() {
alert("test");
});
$("#2").click(function() {
testf();
});
}
testf();
You need to unbind the click event before bind,
function testf() {
$("#1").unbind('click');
$("#1").click(function() {
alert("test");
});
$("#2").unbind('click');
$("#2").click(function() {
testf();
});
}
testf();
Somehow this function is binding your event twice. changing anything here removes the issue
$(".address_field").each(function(index){
var widget = new AddressFinder.Widget(this, "WR3NUKVGC4Q97FPHBJXL");

how can I use focus function and calling a javascript function in asp.net?

I call a function when press the textbox. this is the code for that
onclick="GetColorBack()"
but only when click on the textbox. but if I move with TAB it wont call GetColorBack function.
how can I do that?
PS: not the CSS focus type
For "vanilla"-javascript use onclick="GetColorBack()" onfocus="GetColorBack()"
I think onfocus="GetColorBack()" will be enough, cause clicking lead to focus-event
You can use focus on the textbox. This will work with clicks and tab overs.
Example:
$( "#btnTest" ).focus(function() {
//code
});

JS Function inside a click for a button is being called twice

Hi I have the following piece of code that is giving me weird behaviour
$("#cont_btn").click(function () {
$("#cont_btn").attr('disabled', 'disabled');
selRowIds = $("#CodeGrid").jqGrid('getGridParam', 'selarrrow');
rowsToJson(selRowIds);
//return false;
});
The button cont_btn is a button on a bootstrap 2 modal. It contains a continue button and a close button.
If I select the close button or click outside the modal to dismiss it, and then re-open the modal the function will get called twice.
I have tried using
.one('click', function() { ... }
and I have put break points on the line of
$("#cont_btn").click(...
click is not getting called twice. During my debugging I'm finding that the script re enters on the line of
$("#cont_btn").attr('disabled', 'disabled');
On the page load I see that the line of
$("#cont_btn").click(function () {
Is hit but the code does not enter the function it will skip to the close button. I presume this is the listener for both buttons being initialized ?
Googling this has suggested checking that the Script isn't called twice and using return false, but nothing has worked.
Any help is appreciated.
The event handler is inside the function that opens the modal, so everytime the modal is opened, the event handler is bound once more.

JavaScript window #hash actions

I have two links on the page
Form
Image
I made a simple click.
$('a[href="#Form"]').on('click',function(){
alert("hi");
});
also I'd like HASH works as well.
if(window.location.hash = "#Form"){alert("hi");}
Once the page loads, it shows ALERT, then I click Image link, the url becomes www.myweb.com/#Image, if I press (history) button, the url looks www.myweb.com/#Form BUT alert("hi") isn't working anymore.
Can I make it still works even I press button?
You could try something like:
$(window).on('hashchange',function(){
if(document.location.hash == '#Form'){
alert('hi')
}
});
First your condition is wrong:-
if(window.location.hash = "#Form"){alert("hi");}
to
if(window.location.hash == "#Form"){alert("hi");}
Other thing you need to bind hashchange event. Not all browsers support this event. In that case you need to check hash changes using setInterval function of javascript.

javascript/jquery simulate anchor "tel" click

I have found lots of messages about simulating an anchor click with javascript. Most using the "location" function, which doesn't work for me because I do not want to redirect anywhere. My anchor has href="tel:..." to invoke the iphone's phone function.
I can't have an anchor for clicking, so I wanted to have javascript/jquery simulate that click when a user presses a button, for example. How could I do this (if, indeed, it is even possible)?
Thanks
You can trigger the click event for the anchor on on the click of the button
$('#button1').on('click', function() {
$('#anchor1').click(); // triggering the click event on click of the button
});
Check this FIDDLE
$(function() {
$('a').on('click' , function() {
alert('Fired using button !!')
});
$('#button1').on('click' , function() {
$('a').click();
alert('Button Clicked !!')
});
});​
Try this:
$(your_button).trigger('click')
You could just trigger the click event...
$("a.phonenumber").click();
Here is a simple example of how to accomplish this -
$(function(){
$("#b1").on('click',function(){
alert("pressed b1!");
});
$("#b2").on('click',function(){
$("#b1").trigger('click');
alert("pressed b2!");
});
});​
Clicking on the first b1 button will trigger an alert. When clicking the second b2 button, first we "trigger" a click event on the first button (which will execute it's alert), and then alert the second value.
DEMO
I know the questions asks not to use the location function, but please try this out:
HTML:
<button class="click-to-call" data-phone="2125551234">call</button>
jQuery:
(could easily be written with only javascript too if you wanted to)
$('.click-to-call').on('click',function(){
window.location.assign('tel:'+ $(this).data('phone'));
});

Categories