I have a simple html with a button
I subscribed to mailchimp (newsletter and forms widget)
and I got from them a code for my site that works when
you load the page.
I want the page to execute the code (open the pop up)
only when I click the button. can you help me with it?
(I feel it's kind of a easy one but I'm get a bit scared
cause it's a script code - I don't know why...)
this is my page - in the head there's the script
<html>
<head>
<script type="text/javascript" src="//s3.amazonaws.com
/downloads.mailchimp.com/js/signup-forms/popup/embed.js" data-dojo-`config="usePlainJson: true, isDebug: false"></script>`
<script type="text/javascript">require(["mojo/signup-forms/Loader"], function(L) { L.start({"baseUrl":"mc.us7.list-manage.com","uuid":"d5b6774fb8bf432d69df52d93","lid":"3ed431a3b6"}) })</script>
</head>
<body>
<button type="button">Click Me!</button>
</body>
</html>
also,
I upload it to a server - so this is the page online:
http://judamenahem.com/popuplp2/popup.html
You just have to add to the onClick of the button the code which is in the head who load the current popup.
function myFunction() {
require(["mojo/signup-forms/Loader"], function(L) { L.start({"baseUrl":"mc.us7.list-manage.com","uuid":"d5b6774fb8bf432d69df52d93","lid":"3ed431a3b6"}) });
}
and use :
<button type="button" onclick="myFunction()">Click Me!</button>
You can use standard popup boxes (those boxes that most sites use for: "Hey, you won X, do you really want to leave?") to ask the person a question via alert().
Here is some documentation on them. http://www.w3schools.com/js/js_popup.asp
You would simply need to attach a ClickEventHandler onto your button in your JS that triggers alert().
function myFunction() {
alert("I am an alert box!");
}
<button type="button" onclick="myFunction()">Click Me!</button>
So when you Click on Submit button then it open alert box
There is also prompt() function, which lets the user interact with the box
Related
I am loading Amazon website inside the webview of my app and i want to show a toast message when user clicks the Buy Now button in that loaded website.
What is the way to do perform this task using javascript or any other method available.
Try this maybe if you just want to show a message/alert
<script>
function showAlert() {
alert ("Hello world!");
}
</script>
And set the buttons onCLick property be this function.
For eg.
function myFunction() {
alert("I am an alert box!");
}
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Alert</h2>
<button onclick="myFunction()">Try it</button>
</body>
</html>
I have been trying to use jQuery in order to get some text written on the same page I have opened. I inserted a button, but it is not working on my Django server. After doing some research I noticed that the code works on some servers and doesn't work on others.
For example, I wrote the snippet below and it will be posible to notice that buttons work on it, but when I bring it to my server or to repl.it, the first button never works.
I intend to use exactly the first button example to produce my codes. Can anyone help me to clarify the reasons the above mentioned button doesn't work sometimes?
$("#sentiment_training").click(function(){
/* This is a work in progress yet */
alert("Using jQuery in a File");
});
<html>
<head>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="script.js"></script>
<script>
function myFunction() {
alert("Alert with inline script");
};
$("#sentiment_training3").click(function(){
/* This is a work in progress yet */
alert("Using jQuery Inline");
});
</script>
</head>
<body>
<button id="sentiment_training" name="sentiment_training" class="btn btn-primary mb-2">jQuery in a file</button>
<button id="sentiment_training2" name="sentiment_training2" class="btn btn-primary mb-2" onclick="myFunction()">JavaScript Inline!</button>
<button id="sentiment_training3" name="sentiment_training3" class="btn btn-primary mb-2">jQuery Inline</button>
</body>
</html>
The reason this doesn't work is that the document is not yet loaded at the script's runtime. Moving your scripts to the end of body is a solution. You can also create an event, which will be triggered on document load and run your script afterward.
Put the code inside a $(document).ready(function() {}) block.
This ensures that the code will only run after document is "ready."
$(document).ready(function() {
$("#sentiment_training3").click(function(){
/* This is a work in progress yet */
alert("Using jQuery Inline");
});
})
I want to be able to get an alert with my ip address when I click the button but something strange is happening:
In a normal tab: The site loads and nothing happens when I click the button.
In a private tab: The alert comes and once you press ok the button loads and on pressing nothing happens. The javascript function ran even though I didn't use
How can I fix this?
Thanks in advance
<!DOCTYPE html>
<html>
<head>
<script type="application/javascript">
function getIP(json) {
alert(json.ip);
}
</script>
<script type="application/javascript" src="https://api.ipify.org?format=jsonp&callback=getIP"></script>
</head>
<body>
<button onclick="getIP()">CLICK ME</button>
</body>
</html>
The function getIP is being called when the ipify.org script finishes loading. If you want to only display that ip when the button is clicked, store the ip value to some variable on window in the getIP callback.
<script type="application/javascript">
function getIP(json) {
window.ip = json.ip;
}
</script>
Now on you button you can do this to display the ip:
<button onclick="alert(window.ip)">CLICK ME</button>
or simply:
<button onclick="alert(ip)">CLICK ME</button>
Your button click event doesn't pass in the json parameter when it calls getIP().
Instead the onclick event needs to call another function that will make a request for https://api.ipify.org?format=jsonp&callback=getIP.
I'm trying to use javascript to echo/return the domain name into a displayed document.
I found this code that works by using a button click
But I need it to run automatically when the page is loaded.
The idea is so I have an about page on a site with multiple domains.
So if someone loads foo.com the page says "About FOO.COM" and if someone loads BAR.COM it likewise says "About BAR.COM" on the fly.
<!DOCTYPE html>
<html>
<body>
<p id="demo">Click the button to return the domain name of the server that loaded this document.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction()
{
var x = document.getElementById("demo");
x.innerHTML=document.domain;
}
</script>
</body>
</html>
Just call the function immediately instead of putting it in an event handler.
myFunction();
with jquery:
<div id="yourbutton>your Button</div>
<script>
$(document).ready(function(){
$("#yourbutton").html(document.domain);
});
</script>
without jquery:
search for window.onload
...yay my first post on stackoverflow ;
I wrote a script in which when I press button first time, the window opens and contents are written. But second time I click on button, windows is focus instead of written content again.
Any Idea how to get rid of this?
<script type="text/javascript">
var OpenWindow;
function openwin(url) {
OpenWindow=window.open("", "newwin", "height=250, width=250,toolbar=no,scrollbars="+scroll+",menubar=no");
OpenWindow.document.write("<meta http-equiv=\"refresh\" content=\"2;url="+url+"\">");
OpenWindow.document.close();
self.name="main"
}
</script>
<button onclick="openwin('http://www.google.com/')">Open Window</button>
I think this does what you want:
<script type="text/javascript">
function openwin(url) {
OpenWindow=window.open(url,"main", "height=250, width=250,toolbar=no,scrollbars="+scroll+",menubar=no");
}
</script>
<button onclick="openwin('http://www.google.com/')">Open Window</button>
Your main problem was setting the URL in the body, instead of using the proper method of setting it in the open().