Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

iPad issue with Javascript window.open?

Posted on 2014-08-14
17
Medium Priority
?
329 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?
0
Comment
Question by:Richard Korts
  • 9
  • 8
17 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40261661
Are you saying Case A does work on the customers iPad?
Must be the change event on the Select - try using onblur instead
0
 

Author Comment

by:Richard Korts
ID: 40261687
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
0
 
LVL 58

Expert Comment

by:Gary
ID: 40261699
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

http://www.experts-exchange.com/Q_28247436.html
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Richard Korts
ID: 40261968
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".
0
 
LVL 58

Expert Comment

by:Gary
ID: 40261976
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.
0
 

Author Comment

by:Richard Korts
ID: 40262040
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
0
 
LVL 58

Expert Comment

by:Gary
ID: 40262048
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?
0
 
LVL 58

Expert Comment

by:Gary
ID: 40262049
0
 

Author Comment

by:Richard Korts
ID: 40262130
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;
}
0
 
LVL 58

Expert Comment

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

Open in new window

0
 

Author Comment

by:Richard Korts
ID: 40262137
Gary,

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

Expert Comment

by:Gary
ID: 40262143
It's a workaround, did you try it, it delays the window.open  by a fraction of a second.
0
 

Author Comment

by:Richard Korts
ID: 40263256
You mean lines 2 - 4 of that function would be the first lines in my onchange = function?

Thanks
0
 
LVL 58

Accepted Solution

by:
Gary earned 2000 total points
ID: 40263303
Replace your function with this

function get_cat() {
	setTimeout(function() { 
	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");      
	}
	},100);
}

Open in new window

0
 

Author Comment

by:Richard Korts
ID: 40263407
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
0
 

Author Closing Comment

by:Richard Korts
ID: 40263455
Customer just emailed me: "Works like a Champ".

Richard
0
 
LVL 58

Expert Comment

by:Gary
ID: 40263566
I don't know.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question