I have a parent page with a form in an iframe:
https://profiel.pelckmansuitgevers.be/?email=dennis#hybridmedia.be
All the fields of the form should be prefilled. But that doesn't work anymore.
If you add the email parameter to the url, this parameter is added to the source of the iframe.
But on my iframe, I cannot get the email parameter.
I'm doing this in the iframe:
var urlParams = new URLSearchParams(window.location.search);
if (urlParams.has('email')) {
var email = urlParams.get('email');
//all my code here...
}
It seems that urlParams is empty.
But when I open the page in incognito mode (chrome) and do a hard refresh, all the fields are prefilled. So it works in this case.
Does anyone know what the problem is?
Maybe that my script is trying to receive the email parameter but that this doesn't exist at that moment? Or something else?
Thanks!
You seem to have 2 problems :
1) your iframe is in a subdomain, and you don't send the email parameter in the iframe url. So some browsers like Google Chrome won't be able to access the email.
Sample code for solving this problem :
var loc = window.location.toString(),
params = loc.split('?')[1],
iframe = document.getElementById('updateform');
iframe.src = "https://pelckmans.houston-1.hybridmedia.be/update/pelckmansuitgevers/" + '?' + params + '&v=' + Date.now();
2) JS cache problems
You can solve this with changing
<script src="js/prefill.js"></script>
with
<script>document.write("<script type='text/javascript' src='js/prefill.js.php?v=" + Date.now() + "'><\/script>");</script>
in your iframe page https://pelckmans.houston-1.hybridmedia.be/update/pelckmansuitgevers/
This problem happens often when you develop JS and includes this in a .js file.
The browser caches the js...a way to solve this is for instance to add a timestamp after the js filename, or a version number like i did in my code.
You can find more ways to do this in this thread How to append timestamp to the java script file in <script> tag url to avoid caching
Related
I'm trying to disable facebook's redirection to another country page by restructuring its URL.
An example would be - you're trying to open https://www.facebook.com/VisaID/ but if you're accessing the page from another country, you're going to be redirected to the closes page based on your geolocation (I guess). In my case, it's https://www.facebook.com/VisaCzechRepublic/?brand_redir=272936492828277 and I want to prevent this.
I tried to write a piece of code to solve this, however, when I try to reload the page with restructured URL it somehow adds extra window.location.hostname and window.location.pathname resulting in an absolute mess and breaking the page...
result = https://www.facebook.com/VisaCzechRepublic/www.facebook.com/272936492828277/?brand_redir=DISABLE
Code I used:
//Split URL to get FB ID
var brand = window.location.search;
brand = brand.split("=");
brandId = brand[1];
//Create new URL
//First facebook.com
//Second Page ID
//Third add ?brand_redir=DISABLE at the end
url = window.location.hostname + "/" + brandId + "/" + "?brand_redir=DISABLE";
//Open rearranged URL
window.open(url)
I expected Chrome to open a new URL exactly as is saved in the url being https://www.facebook.com/272936492828277/?brand_redir=DISABLE
but it somehow sneaks in extra https://www.facebook.com/VisaCzechRepublic/ and only after that ads the url I want.
Thanks a ton for any advice!
I have a redirect that happens after a user submits a form. Users should move through the funnel like this:
SiteA.com/submit-form/ ---> SiteB.com/payment/
Problem - The redirect ignores the domain name (i.e. SiteB). It sends visitors to SiteA.com/payment/
Here's the code:
jQuery(document).ready(function(){
var tracker = ga.getAll()[0];
var linkerParam = tracker.get('linkerParam');
var url = 'https://siteB.com/payment/?' + linkerParam;
window.setTimeout(window.location = url, 4000);
});
This code is meant to append Google Analytics cross-domain tracking code. The form plugin (Formidable Pro) also has a redirect option built-in. When activated, it also redirects to the wrong page.
I'm not sure where to start looking. I had added a Category Base in Permalinks. I've just removed it, hoping this might be the problem. Any ideas / help would be greatly appreciated!
window.location return object and in strict mode you will get exception in Chrome.
Full explanation you can find here
You just need
window.setTimeout(function(){window.location.href = url}, 4000);
I'm trying to get pdf.js to work locally on a windows phone app written in Xamarin but I can't understand why if I pass a url without any querystring it works:
url = "Assets/pdfjs/web/viewer.html"
Uri uri = new Uri(url, UriKind.Relative);
PdfWebViewer.Source = uri;
The above displays the pdf.js viewer correctly but with no pdf file of course but if I change the url to:
url = "Assets/pdfjs/web/viewer.html?file=test.pdf"
Uri uri = new Uri(url, UriKind.Relative);
PdfWebViewer.Source = uri;
I just get a page not found. Note the javascript is enabled.
I've added the various web browser events to see if I could spot anything else, and when I call the url without a querystring, it calls the Navigating event followed by the Navigated event but as soon as I specify a querystring, it triggers the Navigating followed by NavigationFailed event but I can't see the error as the exception returned in e.exception is null.
Am I missing something?? Is this not allowed?
Thanks.
UPDATE:
It may not be a problem with Xamarin as I've just tried the same thing in a WP8.1 using the WebBrowser control and I get exactly the same behaviour.
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
WebBrowser.IsScriptEnabled = True
WebBrowser.Source = New Uri("/Html/Viewer.Html?file=1", UriKind.Relative)
End Sub
My Viewer.html is the most basic page you could have:
<html>
<body>
Test
</body>
</html>
Get rid of the query string and the web browser will display Test. Any ideas??
I'm using jquery to rewrite a list of links on the page. If the location.host is NOT the vendor location.host AND the cookie isn't set to a specific value then it locates the links and rewrites them to the alternate values. The code I'm using works great in FF but not in IE7. Please help!
<script type="text/javascript">
// link hider
var hostadd = location.host;
var vendor = '172.29.132.34';
var localaccess = 'internal.na.internal.com';
var unlock = 'http://internal.na.internal.com/Learning/Customer_Care/navigation/newhire.html';
// link rewriter
$(document).ready (
function style_switcher(){
//if not a vendor or not accessing from lms reroute user to lms
if (hostadd != vendor && $.cookie("unlockCookie") != unlock){
var linkData = {
"https://www.somesite.com": "https://internalsite.com/something",'../Compliance/something/index.html':'../somethingelse.html'
};
$("a").each(function() {
var link = this.getAttribute("href"); // use getAttribute to get what was actualy in the page, perhaps not fully qualified
if (linkData[link]) {
this.href = linkData[link];
}
});
}
});
</script>
What you could do, if you insert the links dynamic, is store them in a data attribute like data-orglink="yourlink" which wouldnt be transformed by the browser, then check on that -and if its in the object array - change the href. Do you have access to creating the data attribute?
IE7 have problems with internal links, because it puts the host info on, before JS can reach the link..
http://jsfiddle.net/Cvj8C/9/
Will work in all, but IE7. So you need to use full paths if to use JS for this function :(
You had some errors in your JS.
But it seems to work fine?
See: http://jsfiddle.net/s4XmP/
or am i missing something? :)
I was on Facebook and realised that when I change page the page address changes but the page does not redirect but loads via ajax instead.
You can tell because the console does not clear when you click the link but the URL changes.
Weird, but anyone know how it is done?
Facebook runs with massive AJAX calls that changes the page state and the sections.
So to make a page linkable to somebody by copying the URL address, every time you call an AJAX relevant function they updates the URL using a fake anchor "#!" plus the real address.
Simply when you load the real page (using F5 or linking that so somebody) a JS parser catchs the string after #! (if there is) and redirect you to baseaddress + that.
I belive something like this (untested):
var urlstr = new String(location.href);
var urlparm = urlstr.split('#!');
var last = urlparm.length - 1;
if( (urlparm[last] != urlparm[0]) && (urlparm[last] != "/") )
{ var redir = "http://www.facebook.com" + urlparm[last];
location.href = redir;
}
In Google Chrome instead the URL really changes, I'm according that there is an hash somewhere, but I don't know where and how.