I know that clicking on:
Click here
would quit the current page and go to this address, and that
Click here
would open it in a new tab (default behaviour in Chrome and Firefox).
But how to have a button such that clicking on it would open the external website in a new browser window, possibly 700x500px? (like if you do New window in Chrome menu)
You cannot do that with pure HTML - to achieve the result you need JavaScript.
<a href="http://www.example.com" onclick="window.open('http://www.example.com',
'newwindow',
'width=700,height=500');
return false;">Click here</a>
However, this solution is vulnerable to be pop-up blocked.
As #Rob M. suggested, here you can read everything about window.open().
Related
I search a lot but could not figured it out.
Is it possible to open a new window with tab enabled using window.open() method?.
The way chrome context menu "open link in new window" works.
The browser decides on its own how links will open. Sometimes a user can configure how links are to be opened, but the web page cannot do this.
using an anchor tag you can set the target attribute to have some control over where the link opens. Other than that, this behavior is up to the browser and user and cannot be controlled by javascript.
Use this code
window.open("http:.//www.google.com","DemoName",'scrollbars=1,height=650,width=1050');
I am trying to open a new tab with javascript.
How to write it so that it would work in chrome, firefox and IE7?
(the pages are on the same domain)
UPD: Let's presume that the user uses the default configuration of IE7...
You cannot control how the browser will handle opening new popups / pages. This is entirely handled by the browser. If the user has set their browser up to open new pages/popups in a new window, you cannot force your own page to open in a tab.
Plain HTML:
click here
Javascript:
window.open("newpage.html", "_blank");
But keep in mind what psynnott said.
Using the AddThis plugin (http://www.addthis.com/) I am using the code below to put an email button on my website. But despite setting the target="_blank" it still opens a new tab rather than window. So I am wondering if there is a way to make it open up in a new browser window and not a tab.
<a target="_blank" href="http://api.addthis.com/oexchange/0.8/forward/email/offer? url=${siteURL}/${ourURL}&title=${addThisEmailTitle}" rel="nofollow"><img border="none" src="http://cache.addthiscdn.com/icons/v1/thumbs/email.gif"></img></a>
It all depends on the user and his or her browser defaults.
For example in Chrome target="_blank" opens in a new tab.
The target attribute doesn't help you. AddThis uses a modal pop-up to open the e-mail and other share services (eg. Pinterest). You can use the Addthis Sharing Endpoints that doesn't uses their script and make it work how you want.
I want to open a new window in button click.I have used a code.
Response.Write("<script type='text/javascript'>detailedresults=window.open('YOURPAGE.aspx','_blank');</script>")
It is behaving like a pop up window,but it is not working in IE 7.0 & Chrome.Please help me to solve that issue.Thanks in advance.
In most modern browsers, the browser will prevent the pop-up if the javascript wasn't run as the result of a user action. Actions like onClick are ok, but script that executes as soon as the page loads will usually be blocked.
HTH,
Brian
Why not set the target to _blank on an anchor tag instead of a button? e.g.
<a href="yourpage.aspx" target="_blank" />
Does that work for you?
Due to the prevalence of very irritating adverts and attacks based around opening a popup window as soon as a page loads, most modern browsers will block them.
You can only have a popup if it is direct response to a user event (e.g. in an onclick handler).
You cannot trigger on at page load time.
does anybody know such a problem, window.open()do not work with Firefox suddenly.
<a href="javascript: void(0)"
onclick="window.open('popup.html',
'windowname1',
'width=200, height=77');
return false;">Click here for simple popup window</a>
this always open in a new window (or a new tab), but not open in a popup window.
Thanks,
I find that your code works perfectly. I pasted it into a new HTML page, clicked the link (using Firefox) and voila, new window.
My guess is that you're trying to use the link from a window that already has the name of the window you're trying to create. If the page is presented in a window whose name is already "windowname1", then the browser will put the results of you javascript action in that window instead of popping up a new one.
For example, if the code above is on a page named "popup.html" (the name of the file you open in window.open statement) then it will work the first time (since you haven't yet created a window named "windowname1". Then if you try to click the link again in the new window that popped up (whose name is windowname1), it will just refresh the same window instead of popping a new one.
I don't see why this would happen in firefox only though. I found identical results in Firefox, Chrome, and IE.
if you want to open a pop up window, it's alert('message'). window.open always opened a full window/tab.
(Edited: Even if you specify width/height, most browser allow you to allow javascript but not allow it to resize your windows, and firefox also allows you to force new windows to new tabs)
Maybe you need to add some extra variables to the window.open() method
<a href="#"
onclick="window.open('http://url','windowname1', 'width=200,height=100,scrollbars=yes,toolbar=yes,location=yes'); return false">Link</a>
Add attribute target="_blank" to <a> tag as below. This will open as popup.
<a target="_blank" href="javascript:void(0)">...</a>