window.open not opening window - javascript

I'm trying to open a page in a popup as opposed to new tab - but whichever browser I try this simply opens in a new tab, not popup.
<input type="button" value="new win" onclick="window.open('http://yahoo.com', 'width=500, height=400')" />
Any reason why?

Second parameter must be the window name:
<input type="button" value="new win"
onclick="window.open('http://yahoo.com', 'mywindow', 'width=500, height=400')" />
Working fine in Chrome and Firefox:
http://jsfiddle.net/DvMy5/2/

The second parameter should be name..Something like windowname
<input type="button" value="new win"
onclick="window.open('http://yahoo.com','windowname', 'width=500, height=400')" />

JSFiddle
onclick="window.open('http://yahoo.com', 'MyYahoo', 'width=500, height=400, toolbar=no, menubar=no')" />
window.open method is as follow.
window.open(URL,name,specs,replace)
Here is a good read Window open() Method
name Optional. Specifies the target attribute or the name of the
window. The following values are supported:
_blank - URL is loaded into a new window. This is default
_parent - URL is loaded into the parent frame
_self - URL replaces the current page
_top - URL replaces any framesets that may be loaded
name - The name of the window

Isn't this something controlled by the various browsers? Using target="_blank" opens in a new tab in Chrome, and my guess is that this also apply for Firefox, Opera, Safari and IE.

The problem is the 3rd argument to window.open. When you pass the 3rd argument, the browser will open a new window provided the window name(second argument is not already opened).
window.open("http://localhost:5000", "newWindow", "resizable")will open window but window.open("http://localhost:5000", "newWindow") will open a tab.

Related

Open a url in new and same tab again and again

I'm unable to find the answer.
How can I use window.open to open a link in a new tab?
Repeated calling should reload that same tab and not open a new one.
I've a button when clicked should load an url. Repeated click should reload in the same tab/window.
You need to pass a name as the second parameter to window.open
As long as the tab with that name has not been closed, it will be reused.
You can try this
window.open('http://www.example.com','mywindow');
JSFiddle : https://jsfiddle.net/p26c2atz/
In plain JS
<form>
<input type="button" id="openWindow" value="Open Window" onclick="newTab()">
</form>
<script>
function newTab() {
var form = document.createElement("form");
form.method = "GET";
form.action = "http://www.example.com";
form.target = "newWin";
document.body.appendChild(form);
form.submit();
}
</script>
You can see it in action in https://jsfiddle.net/jprbj21u/
Other way will be:
<form>
<input type="button" id="openWindow" value="Open Window" onclick="window.open('http://www.example.com','newWin')">
</form>
The link will open in a tab named "newWin". As long as you open the same window any new URL will load on it.
Here you can do change target after focusout. I tested and its work.
Link
<script type="text/javascript">
$('a').focusout(function(e) {
$(this).attr('target','_self');
});
</script>
window.open(url,'someconstant',"width=600,height=700")
Here on click-event, there will be a new window opened with the instance named 'someconstant', when you do a click again, the window will be opened again overwriting the previous window as your instance is same!.
Hope this helped.! Happy Coding!

Close popup window opened by a different domain

I have a link in abc domain which opens a popup window and opens a page in a different domain. I need to add a button on the popup which calls window.close() and closes it via javascript. Is is even doable? can I close a popup using windo.close which has been opened by a different domain?
Do you mean something like this:
function openWin(){
myWindow=window.open("http://www.google.co.uk","","width=200,height=100");
}
function closeWin(){
if(myWindow){
myWindow.close();
}
}
hooked up to these buttons:
<input type="button" value="Open 'myWindow'" onclick="openWin()" />
<input type="button" value="Close 'myWindow'" onclick="closeWin()" />
it's a tad crude but should work... I'd also make it unobtrusive if I were you, I've used obtrusive code just to get an answer to you quickly

How to display a message in a pop up window

I have a pop up window function where when a button is clicked the window does pop up. Now the pop up window does not display anything, for a test I want the pop up window to display the word "Session". But I don't know how to do this.
Am I supposed to write the word "Session" in another page and link to that page or is it possible to write the word "Session" on the same page and link it to that section of the page?
I want the latter to happen but I don't know how to do it.
Below is my code:
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Create a Session</title>
<script type="text/javascript">
function openSessionPopup (session) {
window.open(session,
'window',
'width=500,height=500,scrollbars=yes,status=no');
}
</script>
</head>
<body>
<form action="create_session.php" method="post" name="sessionform">
<p><input class="questionBtn" type="button" value="Prepare Questions" name="prequestion" onClick="openSessionPopup(this.href); return false" /></p>
</form>
</body>
Try something like this:
var win = window.open("about:blank", null, "width=400,height=300");
var doc = win.document;
doc.open("text/html");
doc.write("Session");
doc.close();
Try it on JSFiddle.
Alternatively, you can create a new page with the content you want and open that:
window.open("my-new-page.html", null, "width=400,height=300");
If you want to write the word session into the popup.. be sure to use " before and after since it's string... like this window.open("session", 'window', ...
" or ' will do the job either way.
Your popup typically displays another page when it appears. It is this other page that will have the content you want displayed.
This code would never work. When you pass in this.href, the this refers to the input element on which you've clicked. Input elements do not have an 'href' attribute, so you're passing in an undefined value.
You can pass the href as the argument for the "session" parameter. You see this works by putting this code into a file called "question.html" and testing out the button.
Replace the href with the page you want to display.
onClick="openSessionPopup('question.html'); return false"
First parameter in windows.open function is URL. So when you passed an empty value it opened the window with url about:blank (empty page).
If you want open url http://example.com/ in popup window you must use your function as:
openSessionPopup('http://example.com/');

javascript - open frame in new window

I have a page which is displayed in a frame as part of another site. I want to add a link to this page which will allow the user to open the page in a new window i.e. out of the frame. how do I do this?
I have tried using
Remove frame
but this did not work and only opened a new window with the address javascript:window.location.href
<input onclick="javascrpt:window.open(window.location.href);" type="button" value="your value here" />
Try :
<a href="javascript:window.location='whereiwanttogo.html';" target="_blank">
You can use this, it worked for me:
Printable version

HTML - overRide statusbar link location display

when on Mouse Over state on a link the status bar shows the link's location in the status bar like in the following image...
is there a way to change\override this to show some desired text...
Most browsers will block attempts to change the status line by default for security reasons (phishing).
You can try it anyway:
link here
A second approach:
link here
Con: you can't open it in a new tabblad / window using Ctrl + click for example.
In ie9 method 1 does not have any effect. Method 2 also defeats the purpose of concealing info, by placing active file path in status bar, rather than customary interpolated uri:
C:\\\filepath\server\local\whatever
Perhaps there is a way to use method 2. Possibly a proxy link-file location intercept. For example:
click here
where c:\links\anylink links to c:\private\privatefile ...?
Further: 'Con: can't open link in new tab / new window' ... javascript?
This should work
<a href="/www.example.com/contact.html" onmouseover="window.status='Contact'" onmouseout="window.status=''">
If you must change the status, here is a cross browser solution that works:
<a href=".: This a link" onClick="window.location='myurl.html';return false">
Downside is that it requires Javascript
Change "This is a link" to required text" and change "myurl.html" to the path of the window file.
If you need to open a url using "_blank" you can create a function that opens a new window instead.
Unfortunately ".:" has to appear at the front of the text otherwise it will render as a url. Tested in IE9. (Firefox and other browsers render this differently
For other browser you could alternatively use "link:" then your url. Tested in Firefox.
NB: you can only change window.status for Opera, (and possible IE 6 and earlier), for security reasons as mentioned in other people's suggestions.
onmouseover or JavaScript are removed from ckeditor of blog sites when we try to input to a page more data next time. So I think, this method should work tested by me in Firefox browser.
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.btn {
border:none;
}
</style>
<form action="your url">
<input type="submit" class="btn" value="link here">
</form>
</body>
</html>

Categories

Resources