On some pages that have an encoded part in the url, like %FC instead of ü, I get a Uncaught URIError: URI malformed error in the console and the captcha therefore is not working.
Our Project is iso-8859-1 encoded and there is nothing I can change about that.
Do you know a workaround that could fix this? I'm using reCAPTCHA 2.
My solution now is, that before the recaptcha/api.js is executed, I grab the window.location.pathname, get rid of the problematic elements and exchange it in the url with history.pushState. If I'd simply changed the window.location.pathname a page redirect would be the consequence.
Here is my example code:
var oldPath = window.location.pathname;
var newPath = decodeURIComponent( unescape( unescape(oldPath)));
var stateObj = {};
history.pushState(stateObj, "", newPath);
Related
I am trying to build a bookmarklet that will grab the URL from a link that is blocked on my network and run a process on the query string parameters.
I have tried to use window.location.href, but all that is returned is URL of the browsers error page that is displayed, not the URL that generated the error (even though that URL is in the address bar up top.
I get nothing with document.referrer.
This is an example of a URL that this should work on:
https://ue.flipboard.com/usage?data=%7B%22prod_type%22%3A%22notification%22%2C%22event_category%22%3A%22email%22%2C%22event_action%22%3A%22click%22%2C%22event_data%22%3A%7B%22type%22%3A%2210today.media.sat.20210710.436.2%22%2C%22target_id%22%3A%22104t%2F0%22%2C%22url%22%3A%22https%3A%2F%2Fflipboard.com%2F%40businessinsider%2Flabor-shortages-and-calls-for-higher-pay-continue-across-the-us-v632ten2kt4p63a4%3Frefresh%3D1%22%2C%22method%22%3A%22web%22%2C%22redirect_url%22%3A%22https%3A%2F%2Fflipboard.com%2F%40businessinsider%2Flabor-shortages-and-calls-for-higher-pay-continue-across-the-us-v632ten2kt4p63a4%3Frefresh%3D1%22%7D%2C%22properties%22%3A%7B%22uid%22%3A%228606374%22%2C%22unique_id%22%3A%228606374%22%2C%22time%22%3A1626124956022%2C%22ab_tests%22%3A%22436_2%22%7D%7D
javascript:(function() {
let cleanURL = new URL(window.location.href);
console.log(cleanURL);
let urlObj = cleanURL.searchParams.get("data");
urlObj = decodeURIComponent(urlObj);
let jsonObj = JSON.parse(urlObj);
window.location.href=jsonObj.event_data.url;
}());
In the script: `http://theip.com/something/index.php
I have the following javascript URI:
var uri = '/something/script.php?=' + someDynamicValue
That I pass to a function "loadHTML(url, div)"
someDynamicValue can contain spaces and other symbols which make JQuery crash with $.load().
So, I try to encode uri:
$('#'+div).load(encodeURIComponent(uri));
And gives
http://theip.com/something/%2Fsomething%2Fscript.php%3Fq%3D?_=1399924421585
That is, duplicating the /something (which should be an absolute URL so it should go to http://ip.com/something/script.php)
Now if I do the following:
$('#'+div).load(encodeURIComponent(uri).replace(/%2F/g,'/'));
I get a "good" url but gives 404 Error:
http://theip.com/something/script.php%3Fq%3D?_=1399923477529
So I guess it is taking script.php%3Fq%3D?_=1399923477529 as a literal script name, maybe.
How can I fix it? (Encode the rest of the URL).
Thanks!
You just need to encode the one part that isn't already properly URI encoded:
var uri = '/something/script.php?foo=' + encodeURIComponent(someDynamicValue)
$('#'+div).load(uri);
I'm trying to look at the html data returned from a google reverse image search. The URL I'm passing to google contains some characters that get encoded, notably ? changes to %3F, and google doesn't seem to understand the formatted URL (pic_url below). Is there any way to send the URL so that it does not get formatted? Or is there another way around this issue?
My code looks like:
var google_url = "https://www.google.com/searchbyimage?image_url=";
var pic_url = "http://img.cpcdn.com/recipes/_o1f2b886e/50x50c/d9e62798f1c807c1891454bed562e4c9.jpg?u=941483&p=1362455199";
var search_url = google_url + pic_url;
$.getJSON('http://whateverorigin.org/get?url=' +
encodeURIComponent(search_url) + '&callback=?',
function(data){
$("#targetWrapper").html(data.contents);
http_data = data["contents"];
console.log(http_data);
});
The error I get back in the console:
`The requested URL <code>/searchbyimage%3Fimage_url=http%253A%252F%252Fimg.cpcdn.com%252Frecipes%252F_o1f2b886e%252F50x50c%252Fd9e62798f1c807c1891454bed562e4c9.jpg%253Fu%253D941483%2526amp%253Bp%253D1362455199</code>
was not found on this server.
<ins>That’s all we know.</ins>`
But if you just copy and paste https://www.google.com/searchbyimage?image_url=http://img.cpcdn.com/recipes/_o1f2b886e/50x50c/d9e62798f1c807c1891454bed562e4c9.jpg?u=941483&p=1362455199 to the Address Bar it works. Any thoughts?
there is a bug in whateverorigin.org:
https://github.com/ripper234/Whatever-Origin/issues/1
note that the solution proposed doesn't work for me...
I am trying to make a request across domains like that:
var script=document.createElement('script');
script.setAttribute('src',"http://www.example.com/wordpress/register/?callback=callbackF&ver=2.5&url="+encodeURIComponent(window.location.href));
script.setAttribute("type", "text/javascript");
script.setAttribute("id", "spark_grazit_script");
document.getElementById("spark_static_widget").parentNode.appendChild(script);
As the script will be created, it will be appended to the div that i have and there will be a request. At the end of the request:
function callbackF(data){
console.log('Response has finished'+data);
}
That function should be triggered at the end of the request. All I want is to get the callback function called.
I dont get a cross domain error. But I get this error:
Uncaught SyntaxError: Unexpected token :
Is there a way to achieve what I want without resorting to html5 or jsonp. Can I somehow still get a response with ajax?
UPDATE:
The response is a simple json object
This is the response:
{ "userid":"24645", "token":"40A164ECA4DE4A4F", "script":"<script type='text/javascript'>var dbnwid=16211; var dbnpid=23113; var dbnwebid=19459; var dbnlayout=21; var dbncolor='#000000'; var dbntitlefontsize='14'; var dbnbgcolortype=1; var dbnheader='You might enjoy reading:'; var dbnremindercolor=2; var dbn_protocol = (('https:' == document.location.protocol) ? 'https://' : 'http://'); </script>"}
Is there a way to achieve what I want without resorting to html5 or jsonp. Can I somehow still get a response with ajax?
You're not using ajax. You're doing JSONP (or something functionally identical).
The response from http://www.eya.com/wordpress/register/?callback=callbackF&ver=2.5&url= must be a valid script fragment. From your error message, it isn't. (What I get back when I try it is a 404 page, which would tend to be an invalid script.)
Update: Your response is a valid JSON object, but not a valid JavaScript fragment, because the opening { looks like the beginning of a block rather than the beginning of an object literal to the parser, because it doesn't appear where an expression is expected.
To make it work the way you describe (which is JSONP), the response must wrap that object in the call to the callback named in the URL, like this:
callbackF({ "userid":"24645", "token":"40A164ECA4DE4A4F", "script":"<script type='text/javascript'>var dbnwid=16211; var dbnpid=23113; var dbnwebid=19459; var dbnlayout=21; var dbncolor='#000000'; var dbntitlefontsize='14'; var dbnbgcolortype=1; var dbnheader='You might enjoy reading:'; var dbnremindercolor=2; var dbn_protocol = (('https:' == document.location.protocol) ? 'https://' : 'http://'); </script>"})
More about JSONP here.
I have a sample url website: http://mysite.com/
var host = window.location.protocol+"//"+window.location.hostname;
$.ajax({
type:"POST",
data: params,
url : host+'/forms/get_data.php',
success:function(data){
...othercodeblahblah
}
});
Why is it that when I try to check my firebug it makes the URL weird.
This is the sample output of firebug:
http://mysite.com/mysite.com/forms/get_data.php
With this url it now gives me:
"NetworkError: 404 Not Found - http://mysite.com/mysite.com/forms/get_data.php"
Shouldn't it output like http://mysite.com/forms/get_data.php ?
Why is it giving me a wrong url path?
Your help would be greatly appreciated and rewarded!
Thank!
The reason is window.location.protocol already includes a colon (:).
The host variable therefor contains http:://mysite.com
jQuery picks up that you didn't pass a full valid URL, so it prepends your hostname automatically.
The fix is changing
var host = window.location.protocol+"://"+window.location.hostname;
to
var host = window.location.protocol+"//"+window.location.hostname;
Edit
I created a jsfiddle with your code: http://jsfiddle.net/xH5ZV/
and the fixed code: http://jsfiddle.net/xH5ZV/1/
Notice in the fixed code you don't get the hostname twice.
I'm not sure where such an error might come from, but specifying the host is redundant: AJAX requests are same-domain anyway (unless specifically configured), so just specify a part from the root:
url: "/forms/get_data.php",