There's "new windows" and there's "popups". Using target=_blank will open in a new window, except that modern browsers put new windows in new tabs by default. Which sounds like it isn't what you want.
For an actual popup you want window.open(), and be sure to include some specific width and height, otherwise some browsers will still put the new window in a new tab. Darin's example looks good to me.
As for popup blocking, the general approach that browsers take is that popups initiated by user action are allowed (such as clicking), while popups initiated spontaneously through script, such as this, are blocked:
<script type="text/javascript">
window.open("http://www.google.com/", "Google", "width=500,height=500");
</script>
However, ad blocking being an escalating war, you can never be sure that a popup will open. If your popup is blocked, the window.open call returns null. So I would modify Daren's example like this:
<a href="http://www.google.com/"
onclick="return !window.open(this.href, 'Google', 'width=500,height=500')"
target="_blank">
If the popup is blocked, onclick returns true, which follows the link they clicked by opening it in a new window or tab. It's a fallback, so at least the content is accessible (if not pretty).
There's "new windows" and there's "popups". Using target=_blank will open in a new window, except that modern browsers put new windows in new tabs by default. Which sounds like it isn't what you want.
For an actual popup you want window.open(), and be sure to include some specific width and height, otherwise some browsers will still put the new window in a new tab. Darin's example looks good to me.
As for popup blocking, the general approach that browsers take is that popups initiated by user action are allowed (such as clicking), while popups initiated spontaneously through script, such as this, are blocked:
<script type="text/javascript">
window.open("http://www.google.com/", "Google", "width=500,height=500");
</script>
However, ad blocking being an escalating war, you can never be sure that a popup will open. If your popup is blocked, the window.open call returns null. So I would modify Daren's example like this:
<a href="http://www.google.com/"
onclick="return !window.open(this.href, 'Google', 'width=500,height=500')"
target="_blank">
If the popup is blocked, onclick returns true, which follows the link they clicked by opening it in a new window or tab. It's a fallback, so at least the content is accessible (if not pretty).
<a href="http://google.com" onclick="window.open(this.href, 'windowName', 'width=1000, height=700, left=24, top=24, scrollbars, resizable'); return false;">Link</a>
Videos
just using window.open(with out any function) in html solved my problem.
in page1.html i wrote the following script
Copy<script>
window.open("http://google.com", "myWindow", 'width=800,height=600');
window.close();
</script>
When i type page1.html in browser address,it opens google page as a popup.
Thanks everyone for your efforts in trying to help me.
No, there is no such function without user interaction
You could create a dialog() widget with jQuery, however.
See: https://blog.udemy.com/jquery-popup-window/
Demo: http://jsbin.com/yusenu/2/
Here is your working code:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
<li>
<a href="//somesite.com/" rel="nofollow" class="social_share_link">Share</a>
</li>
</ul>
these are the changes you will need to do:
$("a.social_share_link").on("click", function() {
var share_link = $(this).prop('href');
console.log(share_link);
window.open(share_link, "_blank", "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=400,height=400");
});
you can also refer the Working Fiddle here https://jsfiddle.net/9wua66mw/
Just simple call onclick event
- Without extra scripts (Inline)
<a href="//somesite.com/" class="social_share_link"
onclick="return !window.open(this.href, 'somesite', 'width=500,height=500')"
target="_blank">Share</a>
- With extra scripts & jquery`
<a href="//somesite.com/" class="social_share_link" target="_blank">Share</a>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(".social_share_link").click(function(event) {
event.preventDefault();
var share_link = $(this).prop('href');
window.open(share_link, "social_share", "width=500,height=500");
});
</script>
Something like this?
<a href="#" onClick="MyWindow=window.open('http://www.google.com','MyWindow','width=600,height=300'); return false;">Click Here</a>
HTML alone does not support this. You need to use some JS.
And also consider nowadays people use popup blocker in browsers.
<a href="javascript:window.open('document.aspx','mypopuptitle','width=600,height=400')">open popup</a>
Change the window name in your two different calls:
function popitup(url,windowName) {
newwindow=window.open(url,windowName,'height=200,width=150');
if (window.focus) {newwindow.focus()}
return false;
}
windowName must be unique when you open a new window with same url otherwise the same window will be refreshed.
To create a popup you'll need the following script:
<script language="javascript" type="text/javascript">
function popitup(url) {
newwindow=window.open(url,'name','height=200,width=150');
if (window.focus) {newwindow.focus()}
return false;
}
</script>
Then, you link to it by:
<a href="popupex.html" onclick="return popitup('popupex.html')">Link to popup</a>
If you want you can call the function directly from document.ready also. Or maybe from another function.
Default behavior is to open in a new tab. However, using the third parameter windowFeatures in the window.open(...); function will allow you to set parameters to force the request to open in a new popup with the minimal UI elements that you're requesting. For example:
window.open("{url}", "_blank", "popup=yes");
Reference Documentation: window.open()
Specifying the popup option in the windowsFeatures (third) parameter should produce the result you want.
window.open('', '', 'popup=true')
Learn more about window.open from MDN, here.
Hope this helps.