Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-17-2012, 10:10 PM   PM User | #1
cpartsenidis
New to the CF scene

 
Join Date: Sep 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
cpartsenidis is an unknown quantity at this point
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.
cpartsenidis is offline   Reply With Quote
Old 09-17-2012, 10:45 PM   PM User | #2
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,465
Thanks: 0
Thanked 499 Times in 491 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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/
felgall is online now   Reply With Quote
Old 09-18-2012, 08:56 PM   PM User | #3
cpartsenidis
New to the CF scene

 
Join Date: Sep 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
cpartsenidis is an unknown quantity at this point
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.
cpartsenidis is offline   Reply With Quote
Old 09-18-2012, 10:05 PM   PM User | #4
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,465
Thanks: 0
Thanked 499 Times in 491 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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/
felgall is online now   Reply With Quote
Old 09-18-2012, 10:10 PM   PM User | #5
cpartsenidis
New to the CF scene

 
Join Date: Sep 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
cpartsenidis is an unknown quantity at this point
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 !
cpartsenidis is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:27 PM.


Advertisement
Log in to turn off these ads.