Why does IE11 fail to send the post form? - javascript

More details,
I use a simple post Ajax call (used Jquery but also the native XMLhttpRequest with the form encoded as url encoded.
myPost: function(url,form,doneCallback,failedCallback){
var mypost = new XMLHttpRequest();
mypost.onreadystatechange = function() {
if (mypost.readyState === 4){
doneCallback(mypost);
}
};
mypost.onerror = function() {
failedCallback(mypost);
};
mypost.open('POST',url,true);
mypost.setRequestHeader('Content-Length', result.length);
mypost.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
mypost.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
mypost.setRequestHeader('Connection','close');
mypost.send(form);
},
In both situations the code works just fine with Chrome, Safari, Firefox and on IE 11 on win 8.1 or win 7 as a VM on VMWare Fusion, so running on a Mac OsX 10.9.2 with the latest win 8.1 updates installed. However as soon as this code runs on a native windows 8.1 version and IE with the same version for OS and IE, the post forgets to put out the post payload no matter whether I put the above header attributes in or not.
And yes a chrome browser on native win 8.1 properly puts the payload to the server, while the native IE 11 does not put the payload out. The receiving server linux based restlet is missing the payload for the specified resource so further returns a "500" status at the application layer.
There must be some configuration difference with respect to the IE on the native and the VM. As far as I can see this is different from what similar question have described.
BTW on the same native windows 8.1 some posts are working that address a form already created on the web pages, while the above form date is simply filled as.
form = 'options='+encodeURIComponent(options);
Any idea where the different behaviour is created?
Thanks

mypost.setRequestHeader('Content-Length', result.length);
mypost.setRequestHeader('Connection','close');
those lines are only working in FireFox for me, if I remove those 2 lines, my code is working in IE11.

Related

How to detect that browser is running in Safari on iOS 11 via JavaScript?

I want to detect that my JS code in a webpage is running in Safari on iOS 11, which supports some new features.
I can do something like
if (window.navigator.userAgent.includes('OS 11_0')) {
// iOS 11
}
but I believe this is considered unreliable.
Is there some feature or a hack that works only on iOS 11 and not on other OS and can be used to detect that version without inspecting the userAgent?
Update: I am talking about getUserMedia so I am not sure if ther is a way to test it presence without triggering the microphone permission request.
Check out this solution, and then you could do something like this:
ver = iOSversion();
if (ver[0]==11) {
// do something
}
The shared snippet can also be used to detect any specific iOS version, >iOS 2.

How to customize the message "Changes you made may not be saved." for window.onbeforeunload?

I am testing in Google Chrome.
I did some search and found that someone is using:
window.onbeforeunload = function() {
if (hook) {
return "Did you save your stuff?"
}
}
But when I use it, I still got the "Changes you made may not be saved." message. How can I change it to something I want?
You can't, the ability to do this was removed in Chrome 51. It is widely considered a security issue, and most vendors have removed support.
Custom messages in onbeforeunload dialogs (removed):
A window’s onbeforeunload property may be set to a function that returns a string. If the function returns a string, then before unloading the page, a dialog is shown to have the user confirm that they indeed want to navigate away. The string provided by the function will no longer be shown in the dialog. Rather, a generic string not under the control of the webpage will be shown.
Comments
This shipped in Safari 9.1, and has been shipping in Firefox since Firefox 4. Safari considers this a security fix and assigned it CVE-2009-2197 (see https://support.apple.com/en-us/HT206171 ). Approved with the intent https://groups.google.com/a/chromium.org/d/msg/blink-dev/YIH8CoYVGSg/Di7TsljXDQAJ .
Specification
Established standard
Status in Chromium
Removed (launch bug) in:
Chrome for desktop release 51
Chrome for Android release 51
Android WebView release 51
Opera release 38
Opera for Android release 38
In my Vue 2 application, I was able to use: window.onbeforeunload = null; in mounted() and popup does not open after submitting a form.

Sending Data from a UIWebView back to an iOS Application with a custom URL Scheme breaks with Xcode 8/iOS 10

On iOS versions previous to 10, I was able to send information from the JavaScript/HTML loaded into a UIWebView back to my application by creating an iFrame on the document or setting document.location.href to a custom URL which the web view would tried to load:
<html>
<body><input id="clickMe" type="button" value="clickme" onclick="changeWindow();" /></body>
<script type="text/javascript">
function changeWindow() {
//create temp frame
iFrame = this.createIFrame('onStatusChange://eyJ1c2VyTmFtZSI6IkpBTCIsLCJwcm92aWRlciI6IkVtYWlsIn0=');
//remove the frame now
iFrame.parentNode.removeChild(iFrame);
}
function createIFrame(src) {
var rootElm = document.documentElement;
var newFrameElm = document.createElement('IFRAME');
newFrameElm.setAttribute('src', src);
rootElm.appendChild(newFrameElm);
return newFrameElm;
}
</script>
</html>
Then on the client, I would just listen for the UIWebViewDelegate callback webView:shouldStartLoadWithRequest:navigationType:, and check to see if the request.URL.scheme was equal to my custom scheme (in this case onStatusChange).
This is a popular way of communicating between the JavaScript and an iOS app, as seen in popular questions such as How to invoke Objective C method from Javascript and send back data to Javascript in iOS?.
This works on any app built with Xcode 7 (Objective-C or Swift) on iOS 9 and 10 devices. I'm running into an issue where the delegate method is not called on any applications built with Xcode 8. It's as if the web view isn't even trying to load the URL, which in turn is not triggering the delegate callback.
Were there any changes to UIWebView or WebKit from Xcode 7 to 8 or iOS 9 to 10 which would cause this not to work? What's really puzzling to me is that a production app I have built with Objective-C in Xcode 7 targeting iOS 8 works on an iOS 10 device, but a debug build built with Xcode 8 of the exact same codebase does not work.
Ok, long story short we use a special URL scheme onStatusChange:// to send Base64 encoded data from the web view back to our iOS application. I believe UIWebView on iOS 10 chokes when trying to load a URL that ends in one or more equals sign characters, and loads about:blank instead of the actual URL.
Since this works perfectly on iOS 9, I'm assuming this is a defect with iOS 10 and have opened rdar://29035522. A full reproducible example of the issue is available in the body of that radar.
I am reading through the Base-N encoding RFC to determine if it is acceptable to remove the padding = characters at the end of my data string, or if they need to be removed from the web and added on the client before decoding the data.
The solution I ended up implementing was percent-escaping the Base64 encoded data, and unescaping it on the client. Not the most elegant solution, but probably the best for safety.
Thats because iOS now blocks http requests by default. You have to reenable it in your info.plist.
https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW33

HTML 5 Geolocation in China

I'm using the following code in an application in order to retrieve the users location.
function getGeoCoords() {
var deferred = $.Deferred();
navigator.geolocation.getCurrentPosition(deferred.resolve, deferred.reject);
return deferred.promise();
}
This is used by the following:
return deferred.pipe(function() {
console.log('Getting user location. . .');
return getGeoCoords();
}).pipe(function (position)) {
. . .
This code has been tested and works well in all browsers, except Chrome.
It seems that it is also constrained to China. Other browsers tested there (even IE) worked without a hitch. But for some reason, I am unable to use the Geolocation API to retrieve the location of a user in China on Chrome.
Any thoughts?
take a look https://www.zhihu.com/question/20473051
in short, the reason is that the chrome needs to send the location infomation to a google server, but the server may be blocked in china
Six years later I still can't make this work in Chrome.
But there are working examples, so how do they do that?
Here's what my problem is in particular:
I'm in China and I need to make a website that displays a map with a "Get my location" button. To simplify, if I run the following code in debugger, in some environments it will not get my location. Can anyone tell me why?
navigator.geolocation.getCurrentPosition(success => console.log(success), err => console.error(err))
I can get the location in these environments:
My Macbook uses 4G from my phone (hotspot), Safari browser.
PC uses internet from LAN, Edge browser.
I CANNOT get the location in these environments:
My Macbook uses internet from LAN, Safari browser.
PC uses internet from LAN, Chrome version 68 as well as the Chinese QQ browser:
Error: {
code:2,
message:"Network location provider at 'https://www.googleapis.com/' : No response received."
}
PC uses internet from LAN, Chome 103 or Firefox: No success and no error received.
In all cases, location services are enabled and VPN is not used.
I know, googleapis.com is not available in China. But Baidu, Gaode Amap, or QQ Map should work on Chrome and they don't.

Need to open link in IE from FIREFOX

I have developed application in mvc 5 from where I need to open next web application from link which runs only in IE < 9 ;but my application runs in firefox and is NOT supported in IE < 9. So I managed to open the application from Process.Start("IExplore.exe", http); which works fine in debug but while application is hosted it doesn't work. So I need a solution to open application from firefox in IE using backend c# code or javascript.
You can use the below
Process p = new Process();
p.StartInfo.FileName = "iexplore.exe";
p.StartInfo.Arguments = "http:\\\\www.google.com";
p.Start();
This will open Internet Explorer, and immediately load the website passed in as an argument.
Also, the Process class is part of the System.Diagnostics namespace. Be sure to reference it at the top of your code file.
if you are using windows 8 or higher then you can use
System.Diagnostics.Process.Start("IEXPLORE.EXE", MyURLHere)

Categories