[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 292
  • Last Modified:

How can I get a javascript window.open to be executed from another function without causing the popup blocker to complain?

I have two functions that I need to perform from an onchange of a field. One of them also needs to be able to be called independent of the onchange. I have all this working except that when they are called from the onchange the browser complains about the window.open being a popup. If it is called by itself then the browser does not complain even though it is a popup. I am posting both functions in case that might help.

I know just enough JavaScript to get by with what I have to do. If there is a better way to accomplish this I am willing to learn.
function updemailinfo() {
  var scr_action = document.getElementById('Action').value;
  if (scr_action == 'RV') {
    window.open("/Magic94Scripts/mgrqispi94.dll?APPNAME=Web_Dev_Procurement&PRGNAME=update_email_info&ARGUMENTS=-N2331268", "Email_Information", "Scrollbars=yes,menubar=no,toolbar=no,TOP=50,LEFT=50,HEIGHT=360,WIDTH=924");
    } else {
    if (scr_action == 'CV') {
      window.open("/Magic94Scripts/mgrqispi94.dll?APPNAME=Web_Dev_Procurement&PRGNAME=update_email_info&ARGUMENTS=-N2331268", "Email_Information", "Scrollbars=yes,menubar=no,toolbar=no,TOP=50,LEFT=50,HEIGHT=360,WIDTH=924");
    }
  }
}
function updateaction(input) {
  var scr_action = document.getElementById('Action').value;
  if (scr_action == 'RV') {
   document.getElementById('EmailMessage').innerHTML = 'Update Email Information';
   } else {
   if (scr_action == 'CV') {
     document.getElementById('EmailMessage').innerHTML = 'Update Email Information';
      } else {
       document.getElementById('EmailMessage').innerHTML = '';
      }
   }
  }

Open in new window

0
sfletcher1959
Asked:
sfletcher1959
  • 7
  • 6
1 Solution
 
abelCommented:
Popup blockers become better and better. If you manage to get around this time, you may not get around it the next time, or even in another browser or popup blocker that you haven't tested.

The only real full-proof way to prevent being blocked by popup blockers is (except from asking your users to turn them off, which they won't) is to use a javascript popup, which uses simple HTML+DOM+JS techniques to show something that looks like a popup but isn't.

The advantage is not only that the browser will not complain anymore, the advantage is also that the user experience becomes more quiet and easy.

of course, this won't work for every scenario. But for what it's worth, here is a good and very easy one: http://orangoo.com/labs/GreyBox/

-- Abel --
0
 
sfletcher1959VPAuthor Commented:
Abel,

While I tend to agree with you concerning popup blockers and there getting better over time, what I still do not understand it why the popup blocker does not complain if it is a link but if it is from an onchange it does.

I took a look at GreyBox and it looks very nice but I am not sure how I would get it to work with an onchange event. It seems that it is primarily focused on using it for opening another page with an anchor tag. If you know of a way to get this to work from an onchange then this might be the answer I am looking for.
0
 
abelCommented:
> do not understand it why the popup blocker does not complain if it is a link but if it is from an onchange it does.

browsers and popup blockers tend to allow a popup if it is on user's request. On the link click it is OK, but on the onchange, it is not, because that's uncommon behavior (according to the blockers).

I don't really understand what you mean by that you don't know how to do it on an onchange. The way to program for the onchange is equal to for a click. Just wrap the thing in a function and call it from the onchange handler.

If I'm too far off, please show a bit more of the code, or an example bare page with what you mean by the onchange (or just the code that isn't working and/or throwing in an error).

-- Abel --
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
sfletcher1959VPAuthor Commented:
Abel,

I am sorry but I am not well versed in html or JavaScript.

Are you indicating that you can do an href in an onchange? I don't think so because you mention wrapping the thing in a function. I was not aware that you could perform an href from within a function. After a little research I see that you can. I guess I will need to figure out how that works as well unless you are willing to give me an example. :D

Right now I am struggling to get even a simple GreyBox to work. If I just create a page then it works as expected but if I attempt to "merge" my data with the page then it fails. It acts like it can't find the fucntion but if I use the exact same page but don't "merge" data with it then it works. I realize you probably don't have any idea what I am referring to but it is giving me a hard time. :)
0
 
abelCommented:
Can you show me the code you have got so far? Then I'll try to give you a hand...
0
 
sfletcher1959VPAuthor Commented:
Abel,

The code I have for the function is listed with my initial post. It is the first of the two functions and the name is updemailinfo.

As far as the GreyBox is concerned I don't know that showing you the code would help. As I mentioned, if I open the raw html page everything works. It only fails to work if I output it from our application which "merges" some data with it. I modified the program so that it just outputs the html page but it still will not open the way I it does if I just open the raw html. Sorry I don't have a better way of explaining it than that. I am not really looking to you to assist with this issue. I had only mentioned it to let you know I was having some difficulty with it.
0
 
abelCommented:
the reason I asked is: you mention onchange. And that can mean a million things. Can you wrap up a piece of HTML that shows what element you want to react to when it changes?

Don't worry about the GreyBox, I'll help you with that.
0
 
abelCommented:
>  had only mentioned it to let you know I was having some difficulty with it.

I know, but I don't mind to help ;)
0
 
sfletcher1959VPAuthor Commented:
Abel,

I finally got GreyBox working on my "merged" page. This is a great product and I am glad you pointed me to it.

As to the onchange, it is a selection box for an action. Here is the current code:
<select name="Action"  class="StdDropDown" id="act" onChange="updateaction();updemailinfo()">
  <option value="  " selected>* Choose Action *</option>
  <option value="RV" >PO issue to vendor</option>
  <option value="CV" >Pcard issue to vendor</option>
  <option value="CC" >PCard customer managed</option>
  <option value="GJ" >Return Last Approver</option>
  <option value="RJ" >Reject/Cancel Order</option>
</select>

Here is my current link that I have working with GreyBox:
<a href="/Magic94Scripts/mgrqispi94.dll?APPNAME=Web_Dev_Procurement&PRGNAME=update_email_info&ARGUMENTS=-N1322641" rel="gb_page_center[524, 360]"><b>Update Email Information</b></a>

What I am wanting to do is in the second action on the onchange I want to do the same as the link, open the email information for update if they have chosen to send it to the vendor.

As I mentioned my current function was posted with my original post so I won't repost it here. I am going to be working on altering the updemailinfo function to do an href but if you want to take the time I would be interested in seeing what you would do. I like to learn from more experienced people. If I just plug away my self I might get it done but not in a very well structured manner. :)
0
 
sfletcher1959VPAuthor Commented:
Abel,

If you want me to ask a new question concerning GreyBox I can do that so that you might get more points but if you are still willing to assist me then I will give you a little update.

I have so far modified my function so that it now looks like this:
function updemailinfo2() {
  var rel_action = document.getElementById('Release_Action').value;
  if (rel_action == 'RV') {
    window.location.href=GB_showCenter('Email Information','./Magic94Scripts/mgrqispi94.dll?APPNAME=Web_Dev_Procurement&PRGNAME=update_email_info&ARGUMENTS=-N1537590', 824, 380)
    } else {
        if (rel_action == 'CV') {
            window.location.href=GB_showCenter('Email Information','./Magic94Scripts/mgrqispi94.dll?APPNAME=Web_Dev_Procurement&PRGNAME=update_email_info&ARGUMENTS=-N1537590', 824, 380)
            }
        }
    }

In writing this I noticed that I have forgotten the semicolon at the end of the window.location.href lines. Don't know if that will make a difference or not but without them it appeared to start to open and then give me a page could not be found. I suspect that it is a path issue but I replaced my url with www.google.com and still got the same error so the semicolon might be an issue but I don't have a way to test it until tomorrow because they have taken my development box off line for maintenance. :(

Let me know your ideas if you can.

Thanks
0
 
abelCommented:
you are not forgotten, i'm still around but am a bit short on time. I'll get back at you. And of course, if you want faster answers on related stuff, it is always a good idea to ask that, as then thousands of other experts see the question as opposed to a very few amount in this thread...
0
 
sfletcher1959VPAuthor Commented:
Abel,

I got it working.

Thanks very much for your help.
0
 
abelCommented:
Ah, you are apparently quicker than my free time allows... Good you got it working. Was it all too difficult in the end and/or do you understand the underpinnings of this method with GreyBox?
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now