How to open new popup windows in my case? - javascript

I want to open a new window as a popup when user clicks a link and use it as the only popup window if user clicks the links again. I am not sure how to do it.
I have tried
window.open('test/'+id+'.html','','width=1017, height=689', true);
and tried adding different parameter in it but still not sure how to do this.
Can anyone help me about it? Thanks a lot

You can use window name as #Dagg suggested.
window.open('/test1', 'window_name', true);
Then, if you want to open another url in the same popup:
window.open('/test2', 'window_name', true);

Related

Open link in new tab when user clicks

I want to create a jQuery script that opens a specific url in a new tab if the user clicks somewhere (no matter where). After that, the user should be able to click anywhere without getting a new tab at every click again.
Unfortunately I have no idea how to create such a script, and therefore I would appreciate all your answears :)
You can use the .one() event like
$(window).one('click', function() {
var url = "http://google.com";
window.open(url, "_blank");
})
_blank in window.open() is used to open the link in a new tab.
DEMO
Refer to following links for documentation on .one() and window.open()
$(window).one('click', function() {
var url = "http://google.com";
window.open(url, "_blank");
})

How do you create a link which when clicked takes you to a page and also opens a new tab going to another url?

I want to have a link which when clicked preforms two actions:
redirects the current tab of the browser to url A.
opens a new tab directing the browser to url B
How can I do this? Is there HTML for this? Should I use javascript?
You would need to use javascript to achieve this, something along the lines of this:
$('#foo').click(function(e) {
e.preventDefault(); // stop the normal link behaviour so you can open a new window
window.open('http://foo.com/new-page'); // open new tab
window.location.assign($(this).prop('href')); // go to new page in current tab
});
Without jQuery
link // add onclick event
<script>
function f(){
document.location='/a.html'; // open in same tab
window.open('/b.html','_blank'); // open new tab
}
</script>

Open New Tab and Close the Current Tab

Is there any easy work around to close the current tab and open a new tab by javascript?
Try below :
window.open('http://www.google.com','_blank');window.setTimeout(function(){this.close();},1000)
you can use location.replace for same goal:
window.location.replace('https://stackoverflow.com/');
https://developer.mozilla.org/en-US/docs/Web/API/Location/replace
window.open(url,'_blank');
this.close();
window.open will open the new tab according to the user browser settings only. Sorry that I didn't find any way to open an url in new tab if the user's browser settings wont allow you to.
In browser settings, set it to allow popups and then try. This will work.
Instead, to disable back button you can use options given in this page
http://www.irt.org/script/311.htm
var win = window.open('/Employees/GetAttendenceDataBySelectedData/?attendDateString=' + $("#AttendDate").val() + ', "_blank');
window.top.close();

I don't want pop up window to minimize when user clicks away from it

Below is my code for displaying a pop up window when the user clicks on an image link:
Javasript
function plusbutton(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
href=mylink;
else
href=mylink.href;
window.open(href, windowname, 'width=800,height=550,scrollbars=yes');
return false;
}
HTML
<a href="previousquestions.php" onclick="return plusbutton(this, 'previousquestions');">
<image src="Images/plussign.jpg" width="30" height="30" alt="Look Up Previous Question" class="plusimage"/>
</a>
My question is that when the user opens up the window, then when the user clicks away from the window, the window minimizes. I don't want this to happen. If the user clicks away from the window, then it should still display the window.
It is like when you click on "Save As" on Microsfot Word, when the "Save As" window appears, if you click of it, the window still appears, stating that you must either Save the document or Cancel the Save As before being able to do anything else on the document. I want the same this to happen with the pop up window above, how can this be achieved?
Thanks
What you are trying to do is called a "Modal Window", and it is not possible to achieve this goal with a browser window. In fact, you can not even guarantee that it's a window: some browsers would in some cases just open a new tab.
What you should do is open a window with pure HTML within you application. Some librarie allow you to do this easily: jQuery UI dialog for example. Check out http://jqueryui.com/demos/dialog/#modal
If all your architecture bounds your popup content to be delivered by a separate URL, you can do one of the following things:
Either put and iframe in the popup (easy but dirty)
Or retrieve the HTML content with an XMLHttpRequest and use it to define the content of the popup. Maybe a little more tricky, but cleaner.
You should display a modal div, it look like a windows, but it don't dismiss when you click out
if you can use a javascript lib like jQuery, you can do it this way :
$('yourdivselector').dialog({modal : true});
with the modal option set to true
http://docs.jquery.com/UI/Dialog

window opener focus, or active

i want to open a window in a new tab, but when i want that opener page to be active, not the new one. How can i do this... Many thanks
my code is something like this :
<script language="javascript">
window.open("http://www.google.ro");
window.opener.location.focus();
</script>
To give focus to the new window (but you don't want that, and it will probably have focus by default):
var newWindow = window.open("http://www.google.ro", '_blank');
newWindow.focus();
I don't think it's possible to steal the focus from the new opened tabs. I didn't find any official statement telling this, but all the articles I found on this subject talk about configuring your browser to open tabs by default without focus.
The only "solution" I could come up with is this one:
window.open("http://google.com", "_blank");
window.alert('Hello there! This is a message that annoys you, the user.');
Note that it is possible to shift focus when opening popups.
Learn more about the window object.
This works for me...
var newWindow = window.open('http://www.google.ro', '_blank', 'height=300,width=300,menubar=0,status=0,toolbar=0', false);
window.focus();
To give back focus to the opener window, try using window.focus(window.name); instead of window.opener.location.focus();

Categories