We help IT Professionals succeed at work.

iPad issue with Javascript window.open?

Richard Korts
on
768 Views
Last Modified: 2014-08-15
I have some javascript that opens separate windows in certain instances.

Case A looks like this:
if (ac == "b") {
                  dest = "asbuilts/" + cid + ".gif";
                  window.open(dest,"asbuilt","width=800,height=1100,scrollbars=yes,menubar=yes");
                  ac = "";
                  return false;
            }
Case B looks like this:
function get_cat() {
            if (document.st.pcat.value != "") {
                  pcats = document.st.pcat.value;
                  dest = "sel_parts.php?wo=<? print $woid; ?>&ptype=" + pcats;
                  window.open(dest, "woparts","width=800,height=1100,scrollbars=yes,menubar=yes");      
            }
      }
In Case B, the function get_cat is referenced in the html like this:

<select name="pcat" class="pt10" onChange="get_cat();">

In case A, it works on the iPad.

In Case B, it works on my (Gen 1) iPad, it does not work on the customer iPad (probably NOT Gen 1).

Is there any known issue regarding this on iPads?
Comment
Watch Question

CERTIFIED EXPERT
Expert of the Year 2014
Top Expert 2014

Commented:
Are you saying Case A does work on the customers iPad?
Must be the change event on the Select - try using onblur instead
Richard KortsBusiness Owner / Chief Developer

Author

Commented:
To Gary,

You mean "onblur" instead of onchange"? I seem to recall something odd about onchange on a select.

But, on the other hand, according to my Javascript "bible" says it does just what i am expecting.

Doesn't onblur mean when focus goes away from that element?

Thanks,

Richard
CERTIFIED EXPERT
Expert of the Year 2014
Top Expert 2014

Commented:
Yes and Yes
Googling and it does seem to be a problem (and it rings a bell with me as well)
Also seems to be a problem if the select is a multiple select

https://www.experts-exchange.com/Q_28247436.html
Richard KortsBusiness Owner / Chief Developer

Author

Commented:
Since I know that Javascript is case sensitive & I was using  onChange="get_cat();" with a capital C, I changed it to lower case & ask them to try again.

The customer reports this:

"Alan tried the pop up again on his personal iPad as well as three different iPads at the apple store and each time he gets an alert that a pop up is trying to open, but it never does and freezes out the application."

The select in this instance is NOT a multiple.

My guess is that either my iPad is too old & they have changed Safari (I don't think I ever updated, maybe I should), or there is a setting regarding popups in "Settings".
CERTIFIED EXPERT
Expert of the Year 2014
Top Expert 2014

Commented:
Do you know what version of iOS they are on?
There was bugs with alerts /confirms in v7, which while you are opening a popup you are triggering the alert.
Richard KortsBusiness Owner / Chief Developer

Author

Commented:
Gary,

No, but they say they tried it at an Apple store with "several" iPads, which I assume are the latest IOS, etc.

Coming back to "onblur" do you think that would work? My gut feel is it's something about onchange.

Thanks
CERTIFIED EXPERT
Expert of the Year 2014
Top Expert 2014

Commented:
If they are getting the alert then it means the onchange is firing and the freezing when the alert comes up indicates a bug with iOS

Did you try the hack in the link above?
CERTIFIED EXPERT
Expert of the Year 2014
Top Expert 2014

Commented:
Richard KortsBusiness Owner / Chief Developer

Author

Commented:
Gary,

I looked at that link. I don't understand how that applies??

I want to open a window, etc. I'm missing something.

function SetCard(sel) {
   setTimeout(function() { alert('SetCard called successfully.');},10);
    document.getElementById("msg").innerHTML=sel.value + ":" + sel.options[sel.selectedIndex].text;
}
CERTIFIED EXPERT
Expert of the Year 2014
Top Expert 2014

Commented:
function SetCard(sel) {
    setTimeout(function() { 
     document.getElementById("msg").innerHTML=sel.value + ":" + sel.options[sel.selectedIndex].text;
},10);
 } 

Open in new window

Richard KortsBusiness Owner / Chief Developer

Author

Commented:
Gary,

I have no clue what that does & I don't see how it applies in my case.
CERTIFIED EXPERT
Expert of the Year 2014
Top Expert 2014

Commented:
It's a workaround, did you try it, it delays the window.open  by a fraction of a second.
Richard KortsBusiness Owner / Chief Developer

Author

Commented:
You mean lines 2 - 4 of that function would be the first lines in my onchange = function?

Thanks
CERTIFIED EXPERT
Expert of the Year 2014
Top Expert 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Richard KortsBusiness Owner / Chief Developer

Author

Commented:
OK, I did that, it works fine on my Win 7 PC & it works on my iPad (with minor annoyance).

It asks to allow pop-up or not. I answered OK & it opened the window.

In Settings, Safari, I have Block Pop-ups set to off. Why the message?

I asked the customer to try it on his iPad.

Thanks

Richard
Richard KortsBusiness Owner / Chief Developer

Author

Commented:
Customer just emailed me: "Works like a Champ".

Richard
CERTIFIED EXPERT
Expert of the Year 2014
Top Expert 2014

Commented:
I don't know.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.