How to make popup window in javascript only show once? - javascript

I want to make single pop up window in javascript. No matter how many times the button is pressed from parent page, only the single pop up is activated.
How can I do that in Javascript?

Just give the window a fixed name. So, don't do
window.open('popup.jsp');
but do
window.open('popup.jsp', 'chooseHereYourFixedName');
It will then be reused.

The window.open method takes 3 parameters.
a URL
a Name
a list of arguments
As long as the Name portion is the same when you open the popup, the same window will be reused.
window.open ("http://www.google.com","mywindow","status=1");
Here's another idea.
Why not create an inline page popup (div) with an iFrame inside? Fancybox does this pretty easily along with a number of other frameworks. Pretty easy to write with custom Javascript as well.
This way your users will never navigate from your window and only that popup will ever live from clicking the button.

<script>
var popup;
</script>
<input type="button" onClick="if (!popup) popup = window.open('new.html');">

Related

Single mouse click to open new tab + modal window at same time

See for example:
http://www.retailmenot.com/view/macys.com
When you click on one of the buttons, it both automatically opens a new tab, and pop out their modal window.
What are the possible ways to do this?
They seem to do both actions with Javascript. They actually do something that keeps the window in the current tab and not on the one that was opened. How is it done?
In general, Can I achieve these two actions (nevermind if focus is on new window) with a regular form submission with target=_blank the new tab, and some class to pop the modal window? What should the javascript look like?
Is there any way to do this without javascript at all?
Basically I'm looking for practices that are supported from IE8+, and cross browser compliant.
See this : http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_win_open
You can open your js modal also inside myFunction() function.

how to keep javascript window.open variable reference

I have a requirement that I need to create a link to open a form in a new window and then when I click the same link it will focus on the existing window again.
this works well with the following code
<input type="button" value="Click" onclick = "return OpenWindow();"/>
<script>
var win = null;
function OpenWindow()
{
if (win == null || win.closed)
{
win = window.open('http://localhost/Conditions.aspx', 'Condition');
}
win.focus();
return false;
}
</script>
However, I experienced a problem, when I switch to different page and come back to the page which has the link. the variable win will not retain the previous reference.
If I click the link again, it will refresh the existing window (which is not what I want!) and then focus on it.
Is there any way that I can keep variable reference? or does anyone know how to solve this problem?
I had the same issue and was resolved on Window.open only if the window is not open
If you basically want the window focused instead of refreshed when the link is clicked, even if the parent window has been closed, re-opened, or changed, this will do the trick.
I was about to resort to using cookies.
Chia, your problem is that JS doesn't persist across pages.
HTML is stateless, so the JS that sits on top also needs to "forget" what it did on page-1, after you move on to page-2 and page-3.
There are ways of storing strings and numbers, and retrieving them on other pages, but that's not what you're looking for.
And to that end, there's nothing you can really do, with your current setup.
There are different ways of allowing you to keep the child reference (do main-page navigation inside of an iFrame in the main page... if you really, really have to... or AJAX in the page changes, for people with capable browsers, and use old-fashioned navigation for browsers with worse JS engines).
But it's not going to be possible for you to open window2, click on a link which points window1 at page3, and still have page3 have a reference to window2.

How to disable maximize,mimimize and close button for a new window open

I am using window.open() method to open a page as a pop-up window for a link button click event.
But the poup-up window is having minimize,maximize,close(x) button.
I dont want those buttons. How can remove these buttons?
This is the method i am using,
window.open(url,"Link","toolbar=0,location=0,directories=0,status=0,menubar=0,titlebar=no,scrollbars=1,resizable=0,width=450,height=310,left=500,top=350");
Tell me how can do this.
Regards,
Chirag Jain.
You can't.
If you want a popup style window without full window decorations you'd have to create a new overlay <div> on top of the existing content and fill that with content, perhaps using an <iframe>.
You can't do it from javascript alone. Think about it, if you could, then people could put it into code on web-pages and cause other people's computers to open windows they couldn't easily close.
Instead you'll have to look for an answer specific to whichever browser you're using to host this application, and change it on the computers of your users appropriately. Even then though I don't think you'll be in luck (with Firefox for example, I can see how to get rid of them on all browser windows, but not on just one).

open a customized pop up window without address bar using javascript

I need to open a new pop-up window without address bar and i need to display some data in that window. I should be able to modify the data in the pop-up window and once i click on "ok" the pop-up should get closed and the data should get passed to the parent screen which opened this pop-up . Also the popup should have the same css as the parent window .
Please consider using a modal window instead of pop-ups for providing a more decent user experience. You can easily do what you want with a jquery plugin like fancybox.
onclick="window.open('abc.php','addressbar=no')" should do

JavaScript DOM Window

Ok so if I create a window in JavaScript and the parent page changes like to a search page how can I handle the popup window from the page before?
Just call window.open with the same name (second parameter). It will give you back that window instance if it's still open instead of opening a new one.
Not sure what you mean by 'handle'?
However if you want to add content, close the window, give it focus, etc look at the Window Object Methods here: https://developer.mozilla.org/en/DOM/window
Can you be a bit more specific about what you want to do or are try to achieve?

Categories