Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Coding JavaScript PopUp Window

    Greetings to everyone,

    I am trying to use Javascript to do the following:

    - When a user clicks on a button, open a new browser window with specific dimensions (e.g 500x500).
    - The new popup window must be behind the current web browser.

    So far, I've got my script working and does the following:

    - Opens a new browser window (full size)
    - The window pops in front of the current page.

    Here is the code I am using:

    <?php
    if ($ok) {?>
    <script type="text/javascript">
    window.onload=function() {
    var w = window.open("http://www.google.com","_blank");
    if (!w) alert('Sorry, you have blocked popups')
    }
    </script>
    <?php } ?>

    Can someone kindly advise on how I should modify the above code to complete my goal?

    Please note that I am not a programmer and have very limited knowledge on Javascript.

    Many thanks in advanced!

    Chris.

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,603
    Thanks
    0
    Thanked 645 Times in 635 Posts
    1. JavaScript cannot open new windows from onload - it requires an actual action on the part of your visitor to request that a new window be opened and even then they can set their browser so that new windows open as tabs or even overwriting the current window instead.

    2. Where they do allow their browser to open new windows they may have disabled your ability to control where that window opens or how big it is.

    For you to have control of what opes and where you would need to do it within your web page itself. JavaScript has very limited access once you try to do things outside the current web page as most people find such activities to be annoying and so modern browsers allow them to turn those options off.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Stephen,

    Thank you for taking the time to respond to my question.

    The fact is that I have a form which when the user presses the 'Submit' button, a window pops up.

    This is working fine. I just need to adjust the window size and when it pops up, make sure it is sent to the background (behind the current window).

    Any suggestions based on the code I have presented?

    Many thanks once again!

    Chris.

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,603
    Thanks
    0
    Thanked 645 Times in 635 Posts
    You can suggest the window size in the third parameter wassed to the window.open call but some of your visitors will have their browser set to ignore it and it will definitely be ignored where they have their browser set to open a new tab or replace the current page.

    You can try giving the focus to the window that you want in front - most browsers support focus() on windows even though it is not part of the standards - few browsers support blur() on windows.

    Anything involving windows is completely under the control of your visitors - at best your script can contain suggested actions which at least some of your visitors will have their browsers set to ignore.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #5
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Stephen,

    Thanks once again for the reply!

    Would you suggest I try doing what I described in a different way? Perhaps not using Javascript and using something else?

    All I want is when users click the 'submit' form, for it to execute, and open a window at the background. Simple as that.

    Any suggestions/alternatives?

    Thank you !


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •