mylink (the button's this) isn't a string, so you try to open mylink.href:
if (typeof(mylink) == 'string')
href = mylink;
else
href = mylink.href;
But buttons don't have href properties, so it's as if you wrote:
window.open(undefined, 'about', 'width=400,height=200,scrollbars=yes');
which opens a blank page, as expected. If you want to open the same page as the link, use:
onclick="popup('newpopup.html', 'about');"
Answer from Paul Roub on Stack OverflowVideos
Is Popupsmart Compatible with CMS to Display Popup Campaign?
How Can I Ensure a Seamless UX with Popups?
Can I Track the Performance of My Popups?
mylink (the button's this) isn't a string, so you try to open mylink.href:
if (typeof(mylink) == 'string')
href = mylink;
else
href = mylink.href;
But buttons don't have href properties, so it's as if you wrote:
window.open(undefined, 'about', 'width=400,height=200,scrollbars=yes');
which opens a blank page, as expected. If you want to open the same page as the link, use:
onclick="popup('newpopup.html', 'about');"
Try this simple piece of code:
<script>
function fullwindowpopup(){
window.open("newpopup.html","bfs","fullscreen,scrollbars")
}
</script>
<center>
<form>
<input type="button" onClick="fullwindowpopup()" value="CLICK HERE">
</form>
</center>
Give an ID to uniquely identify the button, lets say myBtn
// when DOM is ready
$(document).ready(function () {
// Attach Button click event listener
$("#myBtn").click(function(){
// show Modal
$('#myModal').modal('show');
});
});
JSFIDDLE
Below mentioned link gives the clear explanation with example.
http://www.aspsnippets.com/Articles/Open-Show-jQuery-UI-Dialog-Modal-Popup-on-Button-Click.aspx
Code from the same link
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/jquery-ui.js" type="text/javascript"></script>
<link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/themes/blitzer/jquery-ui.css"
rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(function () {
$("#dialog").dialog({
modal: true,
autoOpen: false,
title: "jQuery Dialog",
width: 300,
height: 150
});
$("#btnShow").click(function () {
$('#dialog').dialog('open');
});
});
</script>
<input type="button" id="btnShow" value="Show Popup" />
<div id="dialog" style="display: none" align = "center">
This is a jQuery Dialog.
</div>
Here is a fiddle that actually does what you want - http://jsfiddle.net/WGPhG/6/
JS
function popUp(){
var popup = document.createElement('div');
popup.className = 'popup';
popup.id = 'test';
var cancel = document.createElement('div');
cancel.className = 'cancel';
cancel.innerHTML = 'close';
cancel.onclick = function (e) { popup.parentNode.removeChild(popup) };
var message = document.createElement('span');
message.innerHTML = "This is a test message";
popup.appendChild(message);
popup.appendChild(cancel);
document.body.appendChild(popup);
}
NOTES
To set the class on an element you use element.className instead of element.class. For the onclick event handler on the cancel element, it is better to directly assign the onclick handler with an anonymous function that does what you need as in my example above.
EDIT (More Efficient Way)
This is actually a much better of getting the results that you want because there is no overhead involved with recreating the elements every time the popup is shown. Fiddle - http://jsfiddle.net/WGPhG/7/
CSS
.popup
{
position:absolute;
top:0px;
left:0px;
margin:100px auto;
width:200px;
height:150px;
font-family:verdana;
font-size:13px;
padding:10px;
background-color:rgb(240,240,240);
border:2px solid grey;
z-index:100000000000000000;
display:none
}
.cancel
{
display:relative;
cursor:pointer;
margin:0;
float:right;
height:10px;
width:14px;
padding:0 0 5px 0;
background-color:red;
text-align:center;
font-weight:bold;
font-size:11px;
color:white;
border-radius:3px;
z-index:100000000000000000;
}
HTML
<button onClick="openPopup();">click here</button>
<div id="test" class="popup">
This is a test message
<div class="cancel" onclick="closePopup();"></div>
</div>
JS
function openPopup() {
document.getElementById('test').style.display = 'block';
}
function closePopup() {
document.getElementById('test').style.display = 'none';
}
Try this update on JSFiddle
Changed :
- Center page (fixed).
- effect (fadein and fadeout)
HTML
<button onClick="openPopup();">click here</button>
<div id="test" class="popup" style="display:none;">
This is a test message
<div class="cancel" onclick="closePopup();"></div>
</div>
CSS
.popup {
position:fixed;
top:0px;
left:0px;
bottom:0px;
right:0px;
margin:auto;
width:200px;
height:150px;
font-family:verdana;
font-size:13px;
padding:10px;
background-color:rgb(240,240,240);
border:2px solid grey;
z-index:100000000000000000;
}
.cancel {
display:relative;
cursor:pointer;
margin:0;
float:right;
height:10px;
width:14px;
padding:0 0 5px 0;
background-color:red;
text-align:center;
font-weight:bold;
font-size:11px;
color:white;
border-radius:3px;
z-index:100000000000000000;
}
.cancel:hover {
background:rgb(255,50,50);
}
JS
function openPopup() {
//document.getElementById('test').style.display = 'block';
$('#test').fadeIn(1000);
}
function closePopup() {
//document.getElementById('test').style.display = 'none';
$('#test').fadeOut(500);
}
you have to call javascript on onClientClick
<asp:Button ID="button1" runat="server" OnClientClick="window.open('BooksAuthor.aspx');" Text="Display" /><br /><br />
Or
<asp:Button ID="button1" runat="server" OnClientClick="openWindow();" Text="Display" /><br /><br />
<script type="text/javascript">
function openWindow() {
window.open("BooksAuthor.aspx", "status=1,width=600,height=300");
}
To open custom sized window the proper syntax is
window.open(URL,name,specs,replace)
EX:-window.open("BooksAuthor.aspx", "MsgWindow", "width=600,height=300");
If you are using Bootstrap , please see below example
<div class="modal fade" id="modelWindow" role="dialog">
<div class="modal-dialog modal-sm vertical-align-center">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Heading</h4>
</div>
<div class="modal-body">
Body text here
</div>
<div class="modal-footer">
<button type="button" data-dismiss="modal" class="btn btn-default">Close</button>
</div>
</div>
</div>
</div>
$('#btn').click(function() {
$('#modelWindow').modal('show');
});
I think the main problem is with this code:
<a href="">
As there is no value in href, so whenever you'll click on the button actually it will click on that anchor tag and the page will refresh. You can use this:
<a href="javascript:void(0);">
Or on the click function you can get the event and use preventDefault.
Hope this will help you. Thanks.
You could use jquery ui dialog, or, if you want to get more ...fancy, you could use fancybox:
$(document).ready(function() {
$("a#inline").fancybox({
'hideOnContentClick': true
});
});
.btn{
border: 1px solid #006;
color:#01ACEE;
font: bold 16px Tahoma;
border-radius:7px;
padding:4px;
}
<link rel="stylesheet" href="http://dodsoftware.com/sotests/fancy/jquery.fancybox-1.3.4.css" type="text/css" media="screen" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript" src="http://dodsoftware.com/sotests/fancy/jquery.fancybox-1.3.4.js"></script>
<script type="text/javascript" src="http://dodsoftware.com/sotests/fancy/jquery.easing-1.3.pack.js"></script>
<script type="text/javascript" src="http://dodsoftware.com/sotests/fancy/jquery.mousewheel-3.0.4.pack.js"></script>
<a id="inline" class="btn" href="#data">My Button</a>
<div style="display:none">
<div id="data">
<img alt="" src="http://farm9.staticflickr.com/8366/8483546751_86494ae914_m.jpg"><br>
<h3>My Cool Title</h3>
<p>Put your cool item descrtiption here</p>
</div>
</div>
You can try jquery ui dialog like,
HTML
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<div id="dialog" title="Basic dialog">
<p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
SCRIPT
$(function() {
$( "#dialog" ).dialog();
});
Also you can try bootstrap modal
why you not try:
<form><input class="btnstylega" onclick="window.open('https://google.com','mywindow',
'menubar=1,resizable=1,width=500,height=500')"
type="button" value="Neue Versicherung hinzufügen" /></form>
Use _blank with the target attribute; this will open a new tab:
<form>
<input class="btnstylega" type="button" value="Neue Versicherung hinzufügen" target="_blank" />
</form>
Or if you want to open a new window, use the onClick attribute:
<button class="button" onClick="window.open('http://www.example.com');">
<span class="icon">Open</span>
</button>
Here, do NOT forget the quotation marks around the "window.open('http://www.example.com');".