Avatar of Richard Korts
Richard Korts
Flag for United States of America asked on

iPad issue with Javascript window.open?

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?
JavaScriptiPad

Avatar of undefined
Last Comment
Gary

8/22/2022 - Mon
Gary

Are you saying Case A does work on the customers iPad?
Must be the change event on the Select - try using onblur instead
Richard Korts

ASKER
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
Gary

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/questions/28247436/iOS-7-onchange-event-is-broken-in-iPad-3-Mini-Need-work-around.html
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Richard Korts

ASKER
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".
Gary

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 Korts

ASKER
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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Gary

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?
Gary

Richard Korts

ASKER
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;
}
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Gary

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

Open in new window

Richard Korts

ASKER
Gary,

I have no clue what that does & I don't see how it applies in my case.
Gary

It's a workaround, did you try it, it delays the window.open  by a fraction of a second.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Richard Korts

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

Thanks
ASKER CERTIFIED SOLUTION
Gary

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Richard Korts

ASKER
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 Korts

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

Richard
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Gary

I don't know.