Google recaptcha 2 doesn't load on clicking link - captcha

I have implemented google recaptcha 2 in footer and welcome pop up. When I browse home page, the captcha loads but when I click any link, the catpcha disappears from footer. This happens in all clicks through out whole site.
Here is snippets I have implemented:
This code goes under head tag:
<script src="https://www.google.com/recaptcha/api.js?onload=myCallBack&render=explicit" async defer></script>
HTML Part:
<div class="field" id="google_recaptcha_container1">
<div id="g-recaptcha1" class="g-recaptcha1" data-sitekey="<?php echo $siteKey ?>" >
</div>
</div>
" >
<script type="text/javascript">
var myCallBack = function () {
//Render the recaptcha2 on the element with ID "recaptcha2"
var recaptcha1 = grecaptcha.render('g-recaptcha1', {
'sitekey': '<?php echo $siteKey; ?>', //Replace this with your Site key
'theme': 'light'
});
var recaptcha2 = grecaptcha.render('g-recaptcha2', {
'sitekey': '<?php echo $siteKey; ?>', //Replace this with your Site key
'theme': 'light'
});
};
Note: This works fine for the first time when page loads but it doesn't if you refresh by clicking refresh button or click any link.
Please suggest.
Thanks in advance.

Related

how to stop page getting loaded from browser history

I am using
$(function(){
$("#header").load("header.html"
$("#footer").load("footer.html");
});
to load header and footer in all the pages of website. But ive a scriptfor menu bar in header.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#flip").click(function(){
$("#panel").slideToggle("very slow");
});
});
function myFunction(x) {
x.classList.toggle("change");
}
</script>
<script type="text/javascript">
window.onload = function() {
alert("sfdfsd");
document.getElementById('panel').style.display = 'none';
};
</script>
----------**************--------------
well the problem is when i load another page the header is not getting completely reloaded. rather than that its getting loaded from history and my menu bar style will be changed to value "block".
Someone pls help me loading header completely on each page.

How to disable button or change value after form submit

I have this code on my View
<h2>#ViewBag.FileContent</h2>
#using (Html.BeginForm("ShowWebSiteLinks", "Home"))
{
<label>WebSite URL:</label>
<input type="text" id="ft" name="fturl" value="http://localhost/search/?sr=100" style="width:350px"><br>
<label>Save to file:</label>
<input type="text" id="filename" name="links_filename" value="links.txt" style="width:200px"><br>
<input id="btnSubmit" type="submit" value="Start" />
}
After i click on submit button, controller call function fine, but submit button stays enabled. I want to prevent multiple clicks on button and want to disable it but not sure how. Ive tried with this javascript but it does not work.
$(document).ready(function () {
$('btnSubmit').click(function (e) {
$(this).attr('disabled', true);
});
});
Can someone help me with this?
Your javascript is almost correct, but the selector is wrong. Try this:
$(document).ready(function () {
$('#btnSubmit').click(function (e) {
$(this).prop('disabled', true);
});
});
Notice the "#" in the selector. This tells jQuery to find by element ID. If you don't put the "#" it will find by element name (i.e. "input", "div", etc...)
Edit:
Here's a good cheat sheet on selectors: http://refcardz.dzone.com/refcardz/jquery-selectors
Edit 2:
Update to use "$(this).prop(...)" rather than "$(this).attr(...)"
Edit 3:
I recommend you place your javascript code at the end of the page (not the head). Something like this:
<html>
<head>[...]</head>
<body>
[...]
<script type="text/javascript">
$(document).ready(function () {
$('#btnSubmit').click(function (e) {
$(this).prop('disabled', true);
});
});
</script>
</body>
</html>
The above answer isn't working for me. I've noticed that if you bind to the click event and immediately disable, you'll actually prevent the form submission from happening.
Instead, I do the following:
<script type="text/javascript">
$(document).ready(function () {
$('#btnSubmit').click(function (e) {
$(this).prop('hidden', true);
});
$('#myform').bind('invalid-form.validate', function () {
$('#btnSubmit').prop('hidden', false);
});
});
</script>
That hides your submit button when the action is clicked but still allows the action to go through. The second statement is there to re-show the button if validation fails. More details on that can be found here: ASP.net MVC Validation Hook

call parent javascript function from iframe

In node-webkit, call from iframe javascript to parent javascript doesnt work for me.
I am trying to launch a link in the iframe on the default browser as a result
I want to call a function in the parent window so as to call:
gui.Shell.openExternal("link");
Any help is appreciated. Thanks in advance.
What you want to do, is to intercept links in the internal frame.
Here we have an iframe where all links will open in the default browser, not in the Node WebKit context. I hope this helps.
Try this:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
window.gui = require('nw.gui');
handleLinks = function(event)
{
var href;
function checkLinks(element)
{
if (element.nodeName.toLowerCase() === 'a')
{
href = element.getAttribute('href');
if (href)
{
gui.Shell.openExternal(href);
// important, prevent the default event from happening!
event.preventDefault();
}
}
else if (element.parentElement)
{
checkLinks(element.parentElement);
}
}
checkLinks(event.target);
};
function isLoaded()
{
// let's see if the iframe has finished loading
var iframe = document.getElementById('myframe');
if (iframe && iframe.contentWindow && iframe.contentWindow.document &&
iframe.contentWindow.document.body &&
iframe.contentWindow.document.body.innerHTML)
{
//now deal with links
iframe.contentWindow.document.body.addEventListener('click', handleLinks, false);
}
else
{
// not yet, let's wait a bit and try again
setTimeout(isLoaded, 300);
}
};
</script>
</head>
<body>
<iframe id="myframe" src="http://www.google.com" onLoad="isLoaded();" style="width: 100%;" seamless="true" nwdisable nwfaketop></iframe>
<div>
Links in the normal browser should still work in the Node Webkit environment.
</div>
<footer>
Whaddayaknow
</footer>
</body>
</html>

Navigation not working as expected in WinJS

Ello!
I have an app bar icon and on the click event - I added a function which has the following code:
function homePage() {
WinJS.Navigation.navigate("/home/homePage.html");
}
Now I have two files - homePage.html which is inside /home/ and the js file for the same.
There's a simple button on html of id NextPage.
While in the homePage.js file, I have:
function () {
"use strict";
WinJS.UI.Pages.define("/home/homePage.html", {
ready: function (element, options) {
var button = document.getElementById("NextPage");
button.addEventListener("click", GoToNextPage);
}
});
function GoToNextPage() {
WinJS.Navigation.navigate("/default.html");
}
})();
But when I click the app bar icon - nothing happens :(
So what I plan to accomplish is that when someone clicks an appbar icon on default.html - the user switches to homePage.html (and then when I click the homePage button - it goes back) - but not even the initial page transfer is taking place.
This is embarrassing to ask but I can't just fold my hands and wait for something magical to happen. I have been working on this for an hour - read videos and samples but it's not working at all.
Would appreciate help - I can't figure out what's going wrong. Thanks!
The WinJS.Navigation namespace provides state and history management, but it doesn't actually do the navigation itself. To move from one page to another, you need to define a handler function for one of the events in the WinJS.Navigation namespace - this lets you respond to call to the WinJS.Navigation.navigate method in a way which makes sense for your app.
As a demonstration, here is a homePage.html file which has a NavBar containing a command that will be the trigger for the navigation.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>NavProject</title>
<link href="//Microsoft.WinJS.1.0/css/ui-dark.css" rel="stylesheet" />
<script src="//Microsoft.WinJS.1.0/js/base.js"></script>
<script src="//Microsoft.WinJS.1.0/js/ui.js"></script>
<link href="/css/default.css" rel="stylesheet" />
<script src="/js/homePage.js"></script>
</head>
<body>
<div id="contentTarget">
<h1>Select a page from the NavBar</h1>
</div>
<div id="navbar" data-win-control="WinJS.UI.AppBar"
data-win-options="{placement:'top'}">
<button data-win-control="WinJS.UI.AppBarCommand"
data-win-options="{id:'NextPage', label:'Next Page',
icon:'\u0031', section:'selection'}">
</button>
</div>
</body>
</html>
Along with the NavBar, I have defined the div element whose id is contentTarget. This is the place in my content where the new file will be loaded when the user clicks the NavBar command.
CLARIFICATION: All of the content that you want replaced needs to go into the contentTarget element. Otherwise you'll get a mix of old and new content displayed.
And here is the JavaScript file which wires it up (this is the homePage.js file which I added a script element for in the HTML file above):
(function () {
"use strict";
WinJS.Navigation.addEventListener("navigating", function (e) {
var elem = document.getElementById("contentTarget");
WinJS.UI.Animation.exitPage(elem.children).then(function () {
WinJS.Utilities.empty(elem);
WinJS.UI.Pages.render(e.detail.location, elem)
.then(function () {
return WinJS.UI.Animation.enterPage(elem.children)
});
});
});
var app = WinJS.Application;
var activation = Windows.ApplicationModel.Activation;
app.onactivated = function (args) {
args.setPromise(WinJS.UI.processAll());
navbar.addEventListener("click", function (e) {
if (e.target.id == "NextPage") {
WinJS.Navigation.navigate("/nextPage.html");
}
}, true);
};
app.start();
})();
Notice how I have added a handler function for the WinJS.Navigation.navigating event. This event is triggered by a call to WinJS.Navigation.navigate and details of the navigation target are contained in the detail.location property of the event object.
In this example, I clear out any content in my target element and replace it with the contents of the target file and animate the transition from one to the other.
You only have to define one handler for the event. This means that if I have elements in nextPage.html that will lead to navigation, I just need to call WinJS.Navigation.navigate without needing to create a new event handler, like this:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script>
WinJS.UI.Pages.define("/nextPage.html", {
ready: function () {
back.addEventListener("click", function () {
WinJS.Navigation.navigate("/homePage.html");
});
}
});
</script>
</head>
<body>
This is next page.
<button id="back">Back</button>
</body>
</html>

Multiple jqModal Windows - onLoad and onClick on the same page. How?

I am using jquery jqModal script for popup windows.
I have one html page with two jqModal windows. I would like one to load when the page opens, and another one opens separately via onClick.
My script is not working. The onLoad works (#success), but the onClick (#dialog) opens both up at the same time.
Here is my current script:
<script type="text/javascript">
$(document).ready(function() {
$('#dialog').jqm();
$('#success').jqm().jqmShow({});
});
</script>
here is the updated code u can try
$(document).ready(function() {
$('#dialog').jqm( {trigger:'#dialog'} );
// $('#dialog').jqmAddTrigger('#dialog');
$('#success').jqm().jqmShow({});
});
Let me know if its working for you
Here you need to add trigger when the modal window will open up
The code you presented works without problems for me. Here is the complete snippet I used:
<script type="text/javascript">
$(document).ready(function() {
$('#dialog').jqm();
$('#success').jqm().jqmShow({});
});
function showModal() {
$('#dialog').jqmShow({});
}
</script>
<div id="dialog" class="jqmWindow">test</div>
<div id="success" class="jqmWindow">test</div>
<input type="button" value="Show Modal" onclick="showModal()"/>