Javascript Popup IE Error - javascript

I've stepped into a new position and am tasked with cleaning up pre-existing code. I will be posting a Javascript function for building hotel reservations by using a base URL and then carrying over variables to the other site.
More clearly, this function allows your to access Site A and search for hotel reservations on Site B. The function makes this even clearer.
function buildReservationURL(){
var site = "http://ach.travel.yahoo.net/hotel/HotelCobrand.do?smls=Y&Service=YHOE&.intl=us&.resform=YahooHotelsCity&";
<!-- Variables Are Defined Here from Form Values //-->
var finishedURL = site + "city=" + cityname + "&state=" + statename + "&dateLeavingDay=" + inDay + "&dateReturningDay=" + outDay + "&adults=" + adults + "&source=YX&distance=&hotelChain=&searchMode=city&cityCountryCode=us&&dateLeavingMonth=" + inMonth + "&dateReturningMonth=" + outMonth;
NewWindow(finishedURL,'Yahoo Travel','780','580','yes','no','1');
}
However, I am receiving an error in IE that gives zero information. The error occurs prior to a window being created so I feel the error would reside somewhere in the function where it is created and the URL is built. This does work fine in FireFox. Any ideas?

Could it be you're using a version of IE that doesn't support spaces in the window name? ("Yahoo Travel" in your example.)

Use IE8's debugger and use "break on error." If it doesn't break in IE8, turn on compatibility view. That uses the IE7 javascript engine while still giving you IE8 debugging facilities.

function NewWindow(mypage,myname,w,h,scroll, menu, res) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height=' + h + ',width=' + w + ',top=' + wint + ',left=' + winl + ',scrollbars=' + scroll +
', resizable=' + res + ', location=no, directories=no, status=yes, menubar=' + menu;
win = window.open(mypage,myname,winprops);
if(parseInt(navigator.appVersion) > 3){
win.window.focus();
}
}

Related

Unexpected characters in output when echo to mobile Safari

I am having a problem when attempting to echo data in a php file to mobile Safari in iOS 7.1.2. Here is the php code:
function swapFlights()
{
var url;
redirect = 1;
airline = <?php echo 'PDT'; ?>;
url = "swap.php?date_one=" + date1 + "&flight_number_one=" + flight1 + "&dep_station_one=" + city1 + "&date_two=" + date2 + "&flight_number_two=" + flight2 + "&dep_station_two=" + city2 + "&redirect=" + redirect + "&airline=" + airline;
window.location.href = url;
}
In mobile Safari on iPhone 5S, the output is the following:
function swapFlights()
{
var url;
redirect = 1;
airline =
2cc1
PDT;
url = "swap.php?date_one=" + date1 + "&flight_number_one=" + flight1 + "&dep_station_one=" + city1 + "&date_two=" + date2 + "&flight_number_two=" + flight2 + "&dep_station_two=" + city2 + "&redirect=" + redirect + "&airline=" + airline;
window.location.href = url;
}
The seemingly random "2cc1" is interjected, and I cannot for the life of me figure out why. It causes a SyntaxError in the parsing of the JavaScript, rendering all of the JavaScript on the page unusable. In every other browser I've tried (desktop Safari, Firefox), the code is output correctly as one would expect:
function swapFlights()
{
var url;
redirect = 1;
airline = PDT;
url = "swap.php?date_one=" + date1 + "&flight_number_one=" + flight1 + "&dep_station_one=" + city1 + "&date_two=" + date2 + "&flight_number_two=" + flight2 + "&dep_station_two=" + city2 + "&redirect=" + redirect + "&airline=" + airline;
window.location.href = url;
}
Any ideas, or is this more likely a bug in mobile Safari itself? I've searched all over the internet, but can't seem to find any other instances of this problem.
Changing the php to:
redirect = 1;
<?php echo 'airline = PDT'; ?>;
results in the unknown characters being slightly different, and appearing earlier in the output:
redirect = 1;
2ccb
airline = PDT;
I should have specified that my goal is the replace the 'PDT' with the string variable $airline. I changed the variable to the literal 'PDT' thinking I may have had a problem with the datatype of the variable, but that wasn't the case.

open window on click of button as modal dialog using javascript

I have to open a window when a button is clicked, as a modal dialog using JavaScript.
I have used window.open, but it shows me two instances, the parent page and the pop-up page.
When the pop-up page is open, then do not allow the user to click on the parent page.
function openWindow() {
var w = 950;
var h = 350;
var t = 0;
var l = 0;
var scrollbars = 1;
var modal = 'yes';
var reportWindow = window.open("Search.aspx" + '', '', "width=" + w + ",height=" + h + ",left=" + l + ",top=" + t + ',scrollbars=' + scrollbars + 'modal' + modal);
reportWindow.focus();
}
Your code line,
reportWindow = window.open("Search.aspx" + '', '', "width=" + w + ",height=" + h + ",left=" + l + ",top=" + t + ',scrollbars=' + scrollbars + 'modal' + modal);
is missing an '=' symbol after modal. It should be,
reportWindow = window.open("Search.aspx" + '', '', "width=" + w + ",height=" + h + ",left=" + l + ",top=" + t + ',scrollbars=' + scrollbars + 'modal=' + modal);
To open window as dialog box,
<html>
<body>
<script language="JavaScript">
function openWindow() {
if (window.showModalDialog) {
window.showModalDialog("http://example.com","name",
"dialogWidth:255px;dialogHeight:250px");
} else {
window.open('http://example.com','name',
'height=255,width=250,toolbar=no,directories=no,status=no, linemenubar=no,scrollbars=no,resizable=no ,modal=yes');
}
}
</script>
<button onclick="openWindow();">Open window</button>
</body>
</html>
If the above code is not working, please use jQuery modal dialog. You can load any urls to dialog using an iframe.
"window.open" will not work. This command always just opens a popup wich is not "always" on top of its parent.
2 Options:
If you just want to let the user enter a search string you could use
prompt("Please enter a search string:", "");
If you have a complexe search form, you have to create a modal dialog for your own.
There are frameworks which provide this functionality (google for "jQuery") or you create it for your own. Should not be hard, tell me if you need some help!

opener.document() won't work on CHROME

Following Script isn't working in CHROME browser, IE is Fine.
I've changed opener.document... to window.opener.document.... but same situation.
It's not closing windows and transfer data to parent page.
function mycoupon() {
window.open("my_coupon3.jsp?amt=<%=pay_price2%>",
'coupon_win',
'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollb‌​ars=yes, resizable=no,width=780,height=540');
}
function sel_coupon(c_id, amt) {
var tot = opener.document.joinform.Org_totalprice.value;
tot = String(Number(tot) - Number(amt));
opener.document.joinform.totalprice.value = tot;
opener.document.joinform.coupon_id.value = c_id;
opener.document.joinform.all["tot"].innerHTML = maskNum(opener.document.joinform.Org_totalprice.value) + "USD - " + maskNum(amt) + " USD <b><font color='red'>Total : " + maskNum(tot) + " USD</font></b> ";
opener.cal_payment_money();
self.close();
}
Define a global variable and assign a reference to the new window then use it in your sel_coupon() function.
Here's an example:
var new_window_handle;
function mycoupon() {
new_window_handle = window.open("my_coupon3.jsp?amt=<%=pay_price2%>",
'coupon_win',
'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollb‌​ars=yes, resizable=no,width=780,height=540');
}
function sel_coupon(c_id, amt) {
var tot = new_window_handle.opener.document.joinform.Org_totalprice.value;
tot = String(Number(tot) - Number(amt));
new_window_handle.opener.document.joinform.totalprice.value = tot;
new_window_handle.opener.document.joinform.coupon_id.value = c_id;
new_window_handle.opener.document.joinform.all["tot"].innerHTML = maskNum(new_window_handle.opener.document.joinform.Org_totalprice.value) + "USD - " + maskNum(amt) + " USD <b><font color='red'>Total : " + maskNum(tot) + " USD</font></b> ";
new_window_handle.opener.cal_payment_money();
self.close();
}
In case you're interested in the reason of this behavior, it's because IE assumes that the default window is the most recent one. So that's why when you run the code on IE it will try to find opener in the new window, but other browsers are a bit more strict (which is better in this case)

ASP.NET Javascript: window.open won't work twice

I have an aspx page with a button. When the user clicks that button, the following javascript opens a new browser window (in this case, 'Reasons.aspx'). Works great. Here's the function for that part:
function ShowPanel(url)
{
var width = 750;
var height = 600;
var left = (screen.width - width) / 2;
var top = (screen.height - height) / 2;
var params = 'width=' + width + ', height=' + height;
params += ', top=' + top + ', left=' + left;
params += ', toolbar=no';
params += ', menubar=no';
params += ', resizable=yes';
params += ', directories=no';
params += ', scrollbars=no';
params += ', status=no';
params += ', location=no';
newwin = window.open(url + '?LetterNumber=1&ReasonType=3', 'd', params); //<--- Change This (LetterNumber) When Copying!
if (window.focus)
{
newwin.focus()
}
return false;
}
Now here's where it gets funky. When this window pops up, there are some controls. One of which is a button, which triggers almost identical code to popup a third window (in this case, ReasonCodes.aspx). Only it won't work. Here's the code for that:
function fGetReasons(url)
{
var width = 750;
var height = 600;
var left = (screen.width - width) / 2;
var top = (screen.height - height) / 2;
var params = 'width=' + width + ', height=' + height;
params += ', top=' + top + ', left=' + left;
params += ', toolbar=no';
params += ', menubar=no';
params += ', resizable=yes';
params += ', directories=no';
params += ', scrollbars=no';
params += ', status=no';
params += ', location=no';
newwin = window.open(url, 'd', params); //<--- Change This (LetterNumber) When Copying!
if (window.focus)
{
newwin.focus()
}
return false;
}
I've set breakpoints on the javascript. It does execute. Here's what's weird -- The above javascript executes, only I don't get a new window with ReasonCodes.aspx. However, I set a breakpoint in the page_load of ReasonCodes.aspx and all of it executes. So the javascript executes, the code-behind page_load of the third page executes, but I don't get a third page.
Instead, the second window (Reasons.aspx) refreshes. It's like my third window is somehow 'hidden'.
Can anybody tell me what's going on, or what am I missing?
Thanks,
Jason
PS -- I know 3 windows sounds like a lot, and it's not by choice. There's a business need here (this is a local intranet application) and I have to abide by the specs. Thanks.
The 2nd parameter to window.open is the name of the window. You are using the same name in both calls so it is attempting to use the same window. Change the name of the 2nd call and you should be fine.
Or use '_blank' name to open each time in new window!

Help with PopUp Function

OK guys... I'm missing something so basic here that it hurts to even ask. Trying to write a basic function that will pop up a window. The author can pass in 3 variables... an ID, a height, and a width. My javascript function looks like this:
function mypopup(pid,h,w)
{
mywindow = window.open('http://www.test.com?pid=" + pid + "', 'mywindow','toolbar=no,location=no,menubar=no,width=" + w + ",height=" + h + ",resizable=no,scrollbars=no')
}
On the HTML file, this is the structure of my links:
text
Can't get it to work... I know I'm missing something easy, can someone help?
call like that : syntax error
function mypopup(pid, h, w) {
mywindow = window.open('http://www.test.com?pid=' + pid , 'mywindow', 'toolbar=no,location=no,menubar=no,width=' + w + ',height=' + h + ',resizable=no,scrollbars=no');
}
<a href="#" onclick='mypopup("K1i2phr4eVEf4BexlfBgym_WM6Ig7U9a","436","503")'>text</a>
text
mywindow = window.open('http://www.test.com?pid=' + pid, 'mywindow','toolbar=no,location=no,menubar=no,width="' + w + '",height="' + h + '", resizable=no,scrollbars=no')
Try these:
text

Categories

Resources