safari target="_blank" and ajax - javascript

I have the following html code:
image
I have the following js functions:
var jsFunction = function(button) {
var site = encodeURIComponent("site name");
var lid = "lid";
var src = "src";
var pf = "platfrom";
$.ajax({
url: "https://www.myurl.com/page.php?site="+site+"&lid="+lid+"&src="+src+"&pf="+pf+"&bt="+button,
async: false
});
}
var jsFunction2 = function() {
var lid = "lid";
var offer = "offer";
var platform = "platfrom";
var site = encodeURIComponent("site name");
var aid = "aid";
var sid = encodeURIComponent("sid");
var placement = "placement";
$.ajax({
url: "https://www.myurl.com/pagetwo.php?lid="+lid+"&offer="+offer+"&platform="+platform+"&site="+site+"&aid="+aid+"&sid="+sid+"&placement="+placement,
async: false
});
window.location = "mypage.php";
}
This seems to function normally in all browsers except Safari 5.1.9 and above. Upon clicking the link it opens a new window/tab and the parent window is directed forward as it should. However, in safari an new window is not opened but the parent window still moves forward. Any ideas as to why safari has this behavior and how to work around or fix it?

Related

Open PDF in window without URL using jQuery

I am not sure if this is possible, but can a PDF be opened in a window without a URL?
I've seen sites where an additional window will open like a pop-up, and it will not have an address bar.
If this is possible with JQuery, how can I edit my code to make this happen:
$('#resultsTable').on('click', 'tr > td > .openPDF', function()
{
var $dataTable = $('#resultsTable').DataTable();
var tr = $(this).closest('tr');
var rowData = $dataTable.row(tr).data();
var rowBookingNum = rowData.JOB_REFERENCE;
var partnerCode = rowData.SHIPPER_CODE;
// path to PDF
var pdf = '../PartnerUploads/' + partnerCode + '/' + rowBookingNum + ".pdf";
$.get(pdf)
.done(function()
{
window.open(pdf);
}).fail(function(textStatus)
{
if(textStatus.status == 404)
{
return false;
}
});
});
I came across this site: https://pdfobject.com/
Really simple to use. Solved my problem.

Infinite loop when redirecting in Javascript

I have a sample page, let' say testpage.pl When I choose English version, GET parameter is added to URL, like /?language=en.
Afterwards, when I click menu positions, they are in the English version so everything is OK.
But if I want to have English version of a subpage directlty after pasting URL in a browser, like
http://testpage.pl/wyjazdy-i-przyjazdy/erasmus-incoming-staff/accommodation.html)
the Polish version is opened. So I've made a simple redirect function like below, but it comes to the loop after first start. This function redirect to the same page, but before it tries to redirect to this first URL with GET parameter ?language=en
How to solve this?
function cleanUrl() {
window.location = "http://testpage.pl/?language=en";
var cleanedUrl = "http://testpage.pl/wyjazdy-i-przyjazdy/erasmus-incoming-staff/accommodation.html";
var currentUrl = window.location.href;
if (currentUrl !== cleanedUrl) {
window.location = cleanedUrl;
}
}
cleanUrl();
Your are updating url in first line of function which is causing your code to loop infinite. Remove that line or move to some other function for fix
function cleanUrl() {
var cleanedUrl = "http://testpage.pl/wyjazdy-i-przyjazdy/erasmus-incoming-staff/accommodation.html";
var currentUrl = "http://testpage.pl/?language=en";
if (currentUrl !== cleanedUrl) {
window.location = cleanedUrl;
}
}
cleanUrl();
Keep the window.location assignment as last operation.
function cleanUrl() {
var enUrl = "http://testpage.pl/?language=en";
var cleanedUrl = "http://testpage.pl/wyjazdy-i-przyjazdy/erasmus-incoming-staff/accommodation.html";
var currentUrl = window.location.href;
if( currentUrl !== cleanedUrl ) { enUrl = cleanedUrl; }
window.location = enUrl;
}

Parent iframe won't reload when popup closes

I have a function in parent iframe.
var reloadFrameWindow = function() {
"use strict";
var doc, myFrame, keyElem, url;
doc = document;
myFrame = doc.getElementById("myFrame");
keyElem = doc.getElementById("key");
if (myFrame && keyElem) {
keyElem.value = keyElem.value + "X";
url = myFrame.src;
url = updateQueryStringParameter(url, "key", keyElem.value);
jQuery.ajax({
type: "GET",
url: url,
success: function() {
myFrame.src = newUrl;
}
});
}
};
In my pop up I have added
window.onbeforeunload = function() {
"use strict";
window.opener.reloadFrameWindow();
};
If I close it on IE11, 8 the parent iframe gets reloaded.
If I close it on chrome, it doesn't reload parent iframe but the key
element value does increase by 1 in both cases.
Note: I want this to fire only when it closes, not when the back button is clicked. But I wouldn't mind if it happens in both cases
actually i found that doing this in chrome works..
jQuery.ajax({
type: 'GET',
url: newUrl,
success: function() {
myFrame.src = newUrl;
}
});

creating new iframe after closing old one

I have an Iframe with fields which sent data to php file through ajax. If it was successful I close (it is working) iframe and create new one with another information (doen't work). So question is: how to close the old iframe and open another one?
so here is ajax function that works but doesn't open a new iframe
$.ajax({
type: "POST",
url: "sign.php",
data: {name : name,
data: canvasData
},
success: function () {
//frame_activation(); //if it will be here it will open iframe inside the old one iframe.
alert('done');
close_frame ();
$(body).html(argument[0]);
//windows.top.frame_activation();
frame_activation(); // does't work
}
});
So the result is - the old iframe sent information and close it, but doesn't open a new iframe.
frame activation :
function frame_activation() {
//document.getElementById('bg_frame').style.visibility = 'visible';
reg = document.createElement('iframe');
document.body.appendChild(reg);
reg.id = 'iframe';
reg.src = 'activate.html';
reg.style.width='600px';
reg.style.height='200px';
position_frame(reg);
reg.style.border='solid 5px #d4d4d4';
alert('here');
return false;
}
function to close iframe:
function close_frame () {
parent.document.getElementById('bg_frame').style.visibility = 'hidden';
var el = parent.document.getElementById('iframe');
el.style.display='none';
parent.document.body.removeChild(el);
return(false);
}
function for creating first iframe with fields
function frame_reg() {
document.getElementById('bg_frame').style.visibility = 'visible';
reg = document.createElement('iframe');
document.body.appendChild(reg);
reg.id = 'iframe';
reg.src = 'frame.html';
reg.style.width='640px';
reg.style.height='400px';
position_frame(reg);
reg.style.border='solid 5px #d4d4d4';
return false;
}
You can change src of iframe to change a page display.
This is sample using Jquery :
$(document).ready(function () {
$("#btnMenu1").click(function () {
$("#myIframe").attr("src", "example.aspx");
});
});

function doesn't work after ajax succesfully sent data

I have an Iframe with formwhi fields wich sent data to php file through ajax. If it was successful I close iframe (it is working) and create new one with another information. So question is: how to close the old iframe and open another one?
so here is ajax function that works but doesn't open a new iframe
the function opening a new iframe work by it self but doesn't work in ajax. Where is a problem?
$.ajax({
type: "POST",
url: "sign.php",
data: {name : name,
data: canvasData
},
success: function () {
//frame_activation(); //if it will be here it will open iframe inside the old one iframe.
alert('done');
close_frame (); //closing frame with form
$(body).html(argument[0]);
//windows.top.frame_activation();
frame_activation(); // does't work, doesn't open a new iframe
}
});
So the result is - the old iframe sent information and close it, but doesn't open a new iframe.
frame activation :
function frame_activation() {
//document.getElementById('bg_frame').style.visibility = 'visible';
reg = document.createElement('iframe');
document.body.appendChild(reg);
reg.id = 'iframe';
reg.src = 'activate.html';
reg.style.width='600px';
reg.style.height='200px';
position_frame(reg);
reg.style.border='solid 5px #d4d4d4';
alert('here');
return false;
}
function to close iframe:
function close_frame () {
parent.document.getElementById('bg_frame').style.visibility = 'hidden';
var el = parent.document.getElementById('iframe');
el.style.display='none';
parent.document.body.removeChild(el);
return(false);
}
function for creating first iframe with fields
function frame_reg() {
document.getElementById('bg_frame').style.visibility = 'visible';
reg = document.createElement('iframe');
document.body.appendChild(reg);
reg.id = 'iframe';
reg.src = 'frame.html';
reg.style.width='640px';
reg.style.height='400px';
position_frame(reg);
reg.style.border='solid 5px #d4d4d4';
return false;
}

Categories

Resources