Example, we have a page:
https://www.facebook.com/חמישה-נוסעים-398064063958835/ (if you open in chrome)
https://www.facebook.com/%D7%97%D7%9E%D7%99%D7%A9%D7%94-%D7%A0%D7%95%D7%A1%D7%A2%D7%99%D7%9D-398064063958835/ (same url if you open in IE).
I need a javascript that will return me https://www.facebook.com/חמישה-נוסעים-398064063958835/ url. This script I'll use only in Chrome browser.
At the moment window.location.href returns the path like IE shows.
Use decodeURIComponent(window.location.href)
Related
I am trying to open an external url from my extension using the window.open method but it opens a different url from what is specified.
I have tried looking for other ways to open a popup to an external url so if you know how plz tell me.
var tipWebsite = "www.gurvirsingh.tk/teddyprivacy/tips/" + response.currentURL.slice(4, -4);
window.open(tipWebsite);
For example window.open(google.com). However instead of opening a new tab or window going to google it goes to "chrome-extension://djhibahmdhdcbfbnjkggbjfnffegdoec/google.com", which obviously doesn't work
A URL should start with a protocol, so https://www.gurvirsingh.tk/... or https://google.com. Otherwise the browser assumes it's a relative URL.
There are many topics of this here, but they all need native code interaction to work.
In my case, it is necessary to be able to do it directly from the url, without any interaction with my mobile app.
I tried:
Open Google in Safari
and
Open
and based in this post.
<script>
$(document).on('click', 'a[target="_blank"]', function (ev) {
var url;
ev.preventDefault();
url = $(this).attr('href');
window.open(url, '_system');
});
</script>
but nothing works.
Anyone have any idea how to fix this?
There is a trick. We know iOS Safari have these available URL Schemes:
(HTTP) — http://websiteurl
(HTTPS) — https://websiteurl
x-web-search://
(FTP) — ftp://locationtofileonftpserver
If you use Click here or window.open("http://somewebsite"). It always use current browser to open url.
x-web-search://?[keyword] - It will switch into Safari app but search for the keyword
Luckily we still have ftp:// left. It will switch to Safari app. But first you need to setup a public folder in your hosting & create a bridge html file to redirect user back to http:
ftp://{youripaddress}/bridge.html
window.open("https://yoururl", "_self");
Now you can open your website in the default Safari app from any browsers.
The original answer is here: JS - Mobile - Open Safari from any browser
Update (2021-01):
Apple seems to fix this on iOS, this is no longer work!
If this is running in safari it should comply with safari async call restrictions regarding popups as explained here.
You should fix your code so that the window open will be outside the function, Something like that:
<script>
var windowReference = window.open();
$(document).on('click', 'a[target="_blank"]', function (ev) {
var url;
ev.preventDefault();
url = $(this).attr('href');
windowReference.location = url;
});
</script>
There isn't a URL Scheme for Safari on iOS.
See Apple's Documentation:
https://developer.apple.com/library/archive/featuredarticles/iPhoneURLScheme_Reference/Introduction/Introduction.html
Have a search around and you will see similar answers:
What is Mobile Safari's custom URL Scheme?
Recently a change happened with Firefox on Android which stopped me from using the work around of adding something to my reading list and opening it from there to force a page into reader mode. With that in mind I tried to find and then finally make a bookmarklet to force a page into reader mode for me.
So far I have found that by adding 'about:reader?url=' to the beginning of a url will try to open any page into reader mode. From there not knowing much about javascript I tried to cludge together something using other examples I found on the web. To start I just figured out how to add to the url and was able to get that working
javascript: window.location = window.location + 'about:reader?url=';
The above will add onto the end just fine but when I move it to the beginning it no longer works so when I try
javascript: window.location = 'about:reader?url=' + window.location;
Nothing happens at all even on a page that will just allow reader mode. When I replace the stuff I am adding with just 'test' though it will happily cause the page to go to 'testhttp://www.google.com/' or wherever else. I have tried it on not only my android phone but also my desktop. What am I doing wrong as from what I can see this should work?
Almost certainly Firefox considers it to be a security risk to allow Javascript to change a page to any location beginning with about:.
Using the Javascript console in Firefox in Windows to run this code:
window.location = 'about:reader?url=' + window.location;
returns error:
Access to 'about:reader?url=...' from script denied
Here is a "work around" that might ease your particular pain:
javascript:(function(){prompt('Copy the below text and then paste it into the URL bar:', 'about:reader?url='+encodeURIComponent(document.location))})();
It will prompt you with a url you can copy and then paste into the URL bar.
In Firefox version 13, bookmarklets (bookmarks with a javascript: URL, e.g. javascript: alert("it works") stopped working. Is there any solution to use javascript: bookmarks in Firefox 13?
This is a consequence of Bug 728313 - Using a bookmark keyword to a bookmarklet fails on new tabs, also Bug 739387 - Aurora 13a New Tab display doesn't allow javascript bookmarks to be selected . This bug affects Firefox 13 onwards.
As a consequence of the fix to bug 723808, javascript: bookmarks are disabled in a just-created new tab. If you first load almost any URL, including about:blank, then a Javascript bookmark will work in that tab.
Note that this is about Javascript bookmarks (bookmarklets). You cannot use this workaround to load javascript: URLs typed directly in the location bar. These have been disabled since Firefox 6, as a consequence of bug 656433 (phishing of javascript: URLs). Bug 680302 is a feature request to allow turning javascript: URLs back on through a preference. Valadrem has written the InheritPrincipal extension to remove this restriction (I haven't tested it). You can still type and run Javascript code in the Scratchpad (press Shift+F4, type code, press Ctrl+R).
There are restrictions on the Javascript you can run from the URL bar or from a bookmark. For example, since Firefox 7, you cannot resize the window (consequence of the fix to bug 565541); the services.sync.prefs.sync.dom.disable_window_move_resize controls this restriction.
NOTE: this solution no longer appears to work as of FF41. See JS Bookmarklets stopped working in Firefox 41.
If you first load almost any URL, including about:blank, then a
Javascript bookmark will work in that tab.
Since Firefox's default behavior for new tabs is about:newtab, which is nothing, and bookmarklets only run once something is loaded, you can do the following to set a default page, and then run bookmarklets:
open about:config
find browser.newtab.url
double-click and change from about:newtab to about:blank (or URI of your choice)
Ctrl-T and run bookmarklets in new tabs!
I have been able to use bookmarklets in recent versions of firefox (I just tested a few on FF23). Two suggestions:
Replace spaces with %20. For instance, try your example bookmarklet code with javascript:alert("it%20works") instead of javascript:alert("it works")
If this isn't enough, enclose the whole bookmarklet inside an anonymous function, so in your example, you'd write javascript:((function(){alert("it%20works");})())
I've created a bookmarklet as follows:
// Assuming a keyword of 'pin',
// 'pin' will retrieve all bookmarks
// 'pin linux' will retrieve all bookmarks tagged 'linux'
// 'pin linux tools' will retrieve all bookmarks tagged both 'linux' and 'tools'
javascript:params='%s';url='http://pinboard.in/u:xiong.chiamiov';if(params!=''){tags=params.split('%20');for(i=0;i<tags.length;i++){url+='/t:'+tags[i];}}location.href=url;
This works as intended on existing pages. However, when a page doesn't actually exist in the current tab (for instance, about:blank), I get nothing, presumably because document.location doesn't yet exist. open(url) does not work, either.
Is there another way to make this work? I'm using Firefox, if it matters.
You code works on my Firefox - page redirect from about:blank to your webpage(http://pinboard.in/u:xiong.chiamiov/t:%s).
I test document.location from a about:blank page, it works too, please try:
Open a about:blank page in Firefox
run javascript:alert(document.location.href);void(0)
*i think you'd better add void(0) at the end on your code.