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().
Related
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 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
I have a simple html that will pop out a new email message for people to send out email.
I need to close a window after the email message popped out. I wish to keep only the email message box.
This is my code, but it's not working:
<html>
<head>
<script type="text/javascript">
function mymessage()
{
location.href = "mailto:abc#com.sg?subject=EmailToEnter";
}
</script>
</head>
<body onload="mymessage()">
<script type='text/javascript'>
settimeout('self.close()',1000);
</script>
</body>
</html>
Try something like this:
function mymessage()
{
var d=document.createElement('A');
d.target='_blank';
d.href='mailto:abc#com.sg?subject=EmailToEnter';
d.click();
}
function closewindow()
{
var d=document.createElement('A');
d.href="javascript:window.open('', '_self', '').close()";
d.click();
}
Or you can use window.open
Also use construction like this
window.setTimeout(function(){closewindow();},1000);
Use this
setTimeout("window.close()", 1000);
BUT
This method is only allowed to be called for windows that were opened by a script using the window.open() method. If the window was not opened by a script, the following error appears in the JavaScript Console: Scripts may not close windows that were not opened by script.
https://developer.mozilla.org/en-US/docs/Web/API/Window.close
I don't know too much about programming but somehow I managed to make a pop-up window work. However, I need that from inside the new window (the pop-up one) a button on the pop-up will open a new tab. But I don't need the new tab open in the main browser, I want it open in the same pop-up.
Is this possible?
How can I do it?
I show both the pop-up code and the redirection code that is, at present, sending people to another tab in my web browser, but I need to do it in the same pop-up window that is already open. Here is the code in the pop-up:
<!DOCTYPE html>
<html>
<body>
<p>Click aquí para escuchar Radio Lineage.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction()
{
window.open("http://localhost:8000/player/index.html");
}
</script>
</body>
</html>
Here the code of the new tab:
<!DOCTYPE html>
<html>
<body>
.
.
<script type="text/javascript" src="http://hosted.musesradioplayer.com/mrp.js"></script>
<script type="text/javascript">
MRP.insert({
'url':'localhost:8000/stream',
'lang':'es',
'codec':'mp3',
'volume':65,
'autoplay':true,
'buffering':5,
'title':'Radio LineageChile',
'welcome':'Bienvenido a...',
'bgcolor':'#FFFFFF',
'skin':'radiovoz',
'width':220,
'height':69
});
</script>
.
.
</body>
</html>
To open new URL in the same popup window, from your code, I edited to below:
var win = window.open("http://localhost:8000/player/index.html", 'newwin', 'height=200px,width=200px');
after run this line, new popup window will be showed with height=200px, width=200px.
To open new URL in the same popup windown (win), use this line
win.location = "http://www.google.com"/
You can replace google URL by any URL you like.
Hope it helpful!
Good luck.
Johnny
Here the code, just a very small code, that will open the new page as a popup window.Code is working properly.
<!DOCTYPE html>
<html>
<body>
<p>Click the button to open an about:blank page in a new browser window that is 1200px wide and 600px tall.</p>
<button onclick="openWin()">Open Window</button>
<script>
function openWin()
{
var myWindow = window.open("","","width=1200,height=600");
}
</script>
</body>
</html>
<script type="text/javascript">
win = null;
function openPopup(){
win = window.open("http://www.google.com", 'newwin', 'height=200px,width=200px');
}
function openOtherUrl(){
win.location = 'http://www.yahoo.com';
}
</script>
you can use this code, I change URl successfully with it.
Hope it will be helpful for you!
click me
How do you auto start this in HTML as onload? Other stuff I researched doesn't work. I only want my website to open up in a new window and has to work with blogspot.
Put it in a script block, not an A-tag.
<script type='text/javascript'>
window.open('website', 'pukarock', 'width=1018, height=715, scrollbars=yes, resizable=yes')
</script>
Don't use href="javascript:void"
It means people without javascript cannot use the link. Use something like this instead.
Click
Then add this to the head of your page
<script>
function openNewWindow(url) {
window.open(url, 'pukarock', 'width=1018, height=715, scrollbars=yes, resizable=yes')
}
</script>
If you want open page after load content, use this:
<!--use some standards of html-–>
<html>
<head>
</head>
<body onload="openSite();">
<script type='text/javascript'>
function openSite()
{
window.open('website','pukarock','width=1018,height=715,scrollbars=yes,resizable=yes');
}
</script>
</body>
</html>
But it could show pop up window warning.