Loading a local page into Firefox with Javascript - javascript

For loading a local file into Firefox I have noticed that...
location.href = "./relative/path/file.htm"; //this works
location.href = "http://localhost/path/file.htm"; //this works
location.href = "file:///c:/absolute/path/file.htm"; //doesnt work (also doesnt work if remove the "file:///" bit)
I would like to get the last example to work. Is there some about.config setting I can add to allow this or maybe a "netscape.security.PrivilegeManager..." statement?
(This is for a special Firefox profile and not for general use so the insecurity issues are not relevant).
Thanks.

http://kb.mozillazine.org/Links_to_local_pages_don%27t_work#Firefox_1.5.2C_SeaMonkey_1.0_and_newer answers this

when using "file:///" you need to use backslashes ( windows ) in other words you need to type
the physical address of the file as it accessed from file explorer ( windows )
dont forget escape with "\\".
example:
var url = "file:///c:\\myDir\\1.html";

Related

Javascript Bookmark to download from youtube to mp3 directly

I am editing a javascript code[the code takes me directly to downloading the video to mp3] since the code provided by the website was not working..i tried editing on my own
This is the code below
javascript:(function() {if (location.href.indexOf('www.youtube.com') > -1) {var uri_enc = encodeURIComponent(location.href).replace(/https%3A%2F%2Fwww.youtube.com%2Fwatch/g,'');var uri_dec = decodeURIComponent(uri_enc);window.open("http://youtubeplaylist-mp3.com/" + uri_dec)}else{alert('sorry youcant');}}) ();
Now the problem here is, I have made a bookmark of this code in chrome, The intention of the bookmark is to run the code when I visit the youtube video page and press the bookmark button.
But for some reason the bookmark doesn't seem to work. so I opened up the console and checked the reason..here are the pictures below of the error..
in console this error comes
on further examining i find that %2F is getting detected as closing '/' so its not detecting the latter part
on further examining i find that %2F is getting detected as closing '/' so its not detecting the latter part
Because of that false detection my bookmark is not working.
However the good news is that if I copy paste the code to console directly and execute then it will work succesfully.
But that is too much work.:p for everyday use.
so help me fix the bookmark please.
UPDATE
Javascript is solved and bookmark is working...
Here below is the complete code..which works for single video and a playlist too..you just need to click on the bookmark when you are on the video page or the playlist page which will direct to download page...
javascript:(function() {if (location.href.indexOf('www.youtube.com') > -1) {var uri_enc = location.href.replace(/https:\/\/www.youtube.com\/watch|https:\/\/www.youtube.com\/playlist/g,'');window.open("http://youtubeplaylist-mp3.com/" + uri_enc);}else{alert('sorry youcant');}}) ();
I am still learning javascript so it took quiet time to understand the answers but thanks to both the coders who answered especially TigOldBitties who gave the complete code from which I understood what the mistake was...Have a nice day..
You need to escape the forward slashes so they don't close the regex
.replace(/https:\/\/www.youtube.com/, '')
LE: The complete answer is that now that you know that you can escape special characters you can drop the needless encoding and just use:
javascript:(function() {if (location.href.indexOf('www.youtube.com') > -1) {var uri_enc = location.href.replace(/https:\/\/www.youtube.com\/watch/g,'');window.open("http://youtubeplaylist-mp3.com/" + uri_enc);}else{alert('sorry youcant');}}) ();
No, it is not a bug.
Bookmarks point to URLs.
You happen to have encoded JavaScript into your URL … and a URL into your JavaScript.
You need to escape the / twice. Once for the http: URL and then again for the javascript: URL.
So / becomes %2F and that becomes %252F

WKWebView doesn't interact anymore with Javascript in iOS10

I have a native app which has to interact with a website. It has been working normally up to iOS 9, but with iOS 10, the Javascript code inside the web app is no longer valid.
Here is an example of the JS code I use on the onClick event of a button, which as mentioned worked like a charm before iOS10.
function DoSomething()
{
var iframe = document.createElement("IFRAME");
var url='codeToBeUsed://id=1230';
iframe.setAttribute("src", url);
document.documentElement.appendChild(iframe);
iframe.parentNode.removeChild(iframe);
iframe = null;
}
when I debug the app on Xcode, the request variable which normally contained the content of the "url" variable on the example provided, now returns a blank value...
<NSMutableURLRequest: 0x170011070> { URL: about:blank }
I even tested placing a alert('click'); but it didn't work either. Does anybody know how to solve this issue?
Using a code close to yours (I pass a stringified json in the src), I also got an embarassing 'about;blank' in the request.
It seems iOs10 has some new restrictions on what you pass to iframe 'src'. I found it requires a valid url to trigger properly the request.
Try to use :
var url='codeToBeUsed://?id=1230';
Edit : or encode URI...

jQuery Script Not Running in IE7

The following code works fine in every other browser except IE7. In fact, with this enabled on the page no scripts will work until I have commented it out.
$(document).ready(function () {
var pathname = $(location).attr('href');
if(pathname.indexOf('sess') === -1){
var path = pathname;
}else{
var path = pathname.replace(/sess[^&]*&?/, "");
}
$.ajax({
type: "POST",
url: "ajax/save_page.php",
data: 'last_page='+path
});
});
I have checked for errant commas and can't find any. If I pass a literal value through the Ajax call and comment out the rest of the function everything begins to work as it should but I need the whole function to work.
Ok, I'm beginning to realise that it isn't going to work on IE7 but I need the script to carry on working as it is without excluding IE7 users completely so I used..
if(navigator.appVersion.indexOf("MSIE 7.")!=-1)
to determine if the browser is IE7 and if so exclude that bit of script. Hopefully the user will be able to persuade their admin to upgrade them to a different browser when they realise that it isn't working as well as it could.
But, for the record, I agree that in an ideal world we shouldn't be supporting IE7 etc but in the real world a lot of people still use it and a lot can't do anything about it. I work within the medical and dental industries and a lot of hospitals etc (about 50%) are still using XP with IE7 with no immediate plans for upgrading despite knowing that XP is no longer supported by Microsoft.
Revision to solution
Ok, I have revised my solution, I am using php sessions now for passing around the sess variable that was previously in the url so I no longer have to try and take it out of the url whilst leaving the rest of the params intact.
So now I am using
var path = window.location.href;
$.ajax({
type: "POST",
url: "ajax/save_page.php",
data: 'last_page='+path
});
Which works fine in all of the browsers I am testing it in including IE7

Android redirect does not work

I need to redirect in a javascript file to a given URI specified by the user.
So a quick example how I do this:
function redirect(uri) {
if(navigator.userAgent.match(/Android/i)) {
document.location.href=uri;
}
window.location.replace(uri);
}
This works fine for everything except Android devices. iOS and all modern Webbrowsers support window.location.replace(...), however Android devices don't do that.
But if I now try to redirect using this function, lets say to "http://www.google.com" the android devices fail to actually redirect to the given url.
Now is it just me being stupid here right now or is there another problem?
Sincerly
p.s. the redirect function is called as an callback from an XML request sent, but that should not be an issue at all.
Android supports document.location without the href property
Try to use:
function redirect(uri) {
if(navigator.userAgent.match(/Android/i))
document.location=uri;
else
window.location.replace(uri);
}
I think it should be window.location.href, not document.location.href.
I would suggest :
location.assign('someUrl');
It's a better solution as it keeps history of the original document, so you can navigate to the previous webpage using back-button or history.back() as explained here.
You can use match and replace in iOS but apparently not in Android. In my experience this is what works for redirects in Android:
<script type="text/javascript"> // <![CDATA[
if ( (navigator.userAgent.indexOf('Android') != -1) ) {
document.location = "http://www.your URL/your HTML file.html";
} // ]]>
</script>
You can just use: window.location = "http://example.com";

ExternalInterface.call using actionscript "eval" only works in firefox not chrome

Chrome doesn't want to let me access javascript from swf file directly in the URL bar (I know that isn't best practice, but that's what I am trying to accomplish):
Given:
/file.swf?cmd=alert();
With the following code (snippet):
flash.external.ExternalInterface.call("eval", cmd);
This only works in Firefox and not in Chrome. I am taking this approach because in chrome the actionscript 2 way to run JS was to use getURL("Javascript:...., however this doesn't work in Chrome either anymore.
Is there a way around this (by calling the file directly in the browser as opposed to be embedded in a page?)- I have my reasons!
Try creating a custom function the proxies the 'eval' function.
Try this in JS...
function exec_code( $value ) {
window.eval( $value );
}
... and this in AS.
var value:String = "[JavaScript Code to execute]";
if ( ExternalInterface.available ) ExternalInterface.call( 'exec_code', value );

Categories

Resources