i'm trying to get the url and title of any website with this javascript we wrote. i made the javascript in a .HTM and get it from out my regedit in the menuExt. like file://C:\Users\lala\script.htm
here's the script
<script type="text/javascript" defer>
javascript:{var jolExt={url:"http://example.com/script_container.php?id=¬e=",submit:function(a){var b=jolExt.base64.encode(jolExt.strip(document.getElementsByTagName("title")[0].innerHTML));var d=jolExt.base64.encode(jolExt.strip(location.href));
window.open(jolExt.url+d+"¬e="+b,"","width=380,height=335")},submitToOtherJol:function(){jolExt.submit(true)},submitToJol:function(){jolExt.submit(false)},strip:function(a){return a.replace(/ {2,}/g," ").replace(/^ +/g,"").replace(/ +$/g,"")},base64:{_0:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(a){var b="";var d,c,h,j,i,f,g;var e=0;a=jolExt.base64._1(a);while(e<a.length){d=a.charCodeAt(e++);c=a.charCodeAt(e++);h=a.charCodeAt(e++);j=d>>2;i=((d&3)<<4)|(c>>4);f=((c&15)<<2)|(h>>6);g=h&63;if(isNaN(c)){f=g=64}else if(isNaN(h)){g=64}b=b+this._0.charAt(j)+this._0.charAt(i)+this._0.charAt(f)+this._0.charAt(g)}return b},decode:function(a){var b="";var d,c,h;var j,i,f,g;var e=0;a=a.replace(/[^A-Za-z0-9\+\/\=]/g,"");while(e<a.length){j=this._0.indexOf(a.charAt(e++));i=this._0.indexOf(a.charAt(e++));f=this._0.indexOf(a.charAt(e++));g=this._0.indexOf(a.charAt(e++));d=(j<<2)|(i>>4);c=((i&15)<<4)|(f>>2);h=((f&3)<<6)|g;b=b+String.fromCharCode(d);if(f!=64){b=b+String.fromCharCode(c)}if(g!=64){b=b+String.fromCharCode(h)}}b=jolExt.base64._2(b);return b},_1:function(a){a=a.replace(/\r\n/g,"\n");var b="";for(var d=0;d<a.length;d++){var c=a.charCodeAt(d);if(c<128){b+=String.fromCharCode(c)}else if((c>127)&&(c<2048)){b+=String.fromCharCode((c>>6)|192);b+=String.fromCharCode((c&63)|128)}else{b+=String.fromCharCode((c>>12)|224);
b+=String.fromCharCode(((c>>6)&63)|128);b+=String.fromCharCode((c&63)|128)}}return b},_2:function(a){var b="";var d=0;var c=c1=c2=0;while(d<a.length){c=a.charCodeAt(d);if(c<128){b+=String.fromCharCode(c);d++}else if((c>191)&&(c<224)){c2=a.charCodeAt(d+1);b+=String.fromCharCode(((c&31)<<6)|(c2&63));d+=2}else{c2=a.charCodeAt(d+1);c3=a.charCodeAt(d+2);b+=String.fromCharCode(((c&15)<<12)|((c2&63)<<6)|(c3&63));d+=3}}return b}}};jolExt.submitToJol();}
when i'm using my add-on i made i only get the path i set on the regedit in the menuExt. Does any1 know's how to solve this. i alraidy tried to putt the full javascript in the string value but it didn't help.
so in short language, i am asking the url but i get the path of my regedit editor in the menuExt. and i need the url of the parent site and the title of the parent site.
Plz help me :)
Regards,
Freezingmoon
The problem is that the document instance in your script is the MenuExt script's document. What you need is the document from which the script was called.
To get this use the external.menuArguments object. This contains the window of the callee. Consider this simple MenuExt script
<script type="text/javascript">
// Get callee's 'window' object
var win = external.menuArguments;
// Get the callee's 'document' object.
var doc = win.document;
// Get the callee's object which invoked this
// (aka: what you right-clicked on)
var src = win.event.srcElement;
// Spit back page title and URL
alert('Viewing ' + doc.title + ' at ' + win.location +
'. You clicked on ' + src + '.');
</script>
To get the item right-clicked on, use external.menuArguments.event.srcElement, as shown above.
Related
I've added a random date param to my CSS and JS files in order to "cache-bust"...
HTML (head)
<!-- STYLE -->
<link href="assets/css/style.css" rel="stylesheet" id="style">
<!-- SCRIPTS -->
<script src="assets/js/scripts.js" id="scripts"></script>
JS (jQuery 3.4.1)
var randomParam = new Date().getTime();
// CSS
var ogCSS = $("head").find("#style").attr("href");
$("head").find("#style").attr("href", ogCSS + "?" + randomParam);
// JS
var ogJS = $("head").find("#scripts").attr("src");
$("head").find("#scripts").attr("src", ogJS + "?" + randomParam);
The CSS file works great. The JS file not so much.
"Network" tab (CSS renamed and called again, JS is not)...
"Sources" tab (JS not called again, has original name)...
I cannot use PHP. I cannot access the server. This is all client-side.
What can I do to make it work? Or is this just how it is?
UPDATE
Forgot to mention that "Elements" in the DevTools show the JS file being renamed properly (see below). It's just not being re-called in "Network" or showing up as being renamed in "Sources". So it's stuck in cache.
I know this question is old, but in case someone comes across it (as I did), the problem is likely here:
ogCSS + "?" + randomParam
That does not create a valid and complete query string. The format of the query string should be:
?<param_name>=<param_value>
but in the code above, we only have ?<param_value>. This means the value will be treated as a name, presumably with a null value, which is generally ignored by most servers I have worked with. To make this correct, you would need to append both a parameter name (often "_" for this use case) and a value, so something like:
ogCSS + "?_=" + randomParam
I have a parent page with a form in an iframe:
https://profiel.pelckmansuitgevers.be/?email=dennis#hybridmedia.be
All the fields of the form should be prefilled. But that doesn't work anymore.
If you add the email parameter to the url, this parameter is added to the source of the iframe.
But on my iframe, I cannot get the email parameter.
I'm doing this in the iframe:
var urlParams = new URLSearchParams(window.location.search);
if (urlParams.has('email')) {
var email = urlParams.get('email');
//all my code here...
}
It seems that urlParams is empty.
But when I open the page in incognito mode (chrome) and do a hard refresh, all the fields are prefilled. So it works in this case.
Does anyone know what the problem is?
Maybe that my script is trying to receive the email parameter but that this doesn't exist at that moment? Or something else?
Thanks!
You seem to have 2 problems :
1) your iframe is in a subdomain, and you don't send the email parameter in the iframe url. So some browsers like Google Chrome won't be able to access the email.
Sample code for solving this problem :
var loc = window.location.toString(),
params = loc.split('?')[1],
iframe = document.getElementById('updateform');
iframe.src = "https://pelckmans.houston-1.hybridmedia.be/update/pelckmansuitgevers/" + '?' + params + '&v=' + Date.now();
2) JS cache problems
You can solve this with changing
<script src="js/prefill.js"></script>
with
<script>document.write("<script type='text/javascript' src='js/prefill.js.php?v=" + Date.now() + "'><\/script>");</script>
in your iframe page https://pelckmans.houston-1.hybridmedia.be/update/pelckmansuitgevers/
This problem happens often when you develop JS and includes this in a .js file.
The browser caches the js...a way to solve this is for instance to add a timestamp after the js filename, or a version number like i did in my code.
You can find more ways to do this in this thread How to append timestamp to the java script file in <script> tag url to avoid caching
I have a SWF advert that needs to call the Facebook API, for which I need the following single-line reference in the host HTML page:
<script type="text/javascript" src="//connect.facebook.net/en_US/all.js"></script>
Since I am dealing with an advert, I don't have control over the host page. I understand I can inject functions into a page (there's a good reference for this here: http://www.actionscript.org/resources/articles/745/4/JavaScript-and-VBScript-Injection-in-ActionScript-3/Page1.html), but I haven't found a way to add a reference to an externally-hosted script.
Does anybody know if this can be done, and if so, how?
Just add a SCRIPT tag dynamically to the document. You can do that by running a anonymous function through ExternalInterface:
var js:Array = [
'var script = document.createElement("SCRIPT")',
'script.src = "http://connect.facebook.net/en_US/all.js"',
'var head = document.getElementsByTagName("HEAD")[0]',
'head.appendChild(script)'
];
ExternalInterface.call('(function(){' + js.join(';') + '})()');
I've done some research on the subject, but can't get a clear answer with how to go about doing this. I have tried the following method:
<script type="text/javascript" src="../binaryajax/binaryajax.js" ></script>
<script type="text/javascript" src="id3.js" ></script>
var file = "mymusicfile.mp3";
// define your own callback function
function mycallback() {
// either call ID3.getAllTags([file]) function to return object holding all the tags
alert(
"All tags in this file: " + ID3.getAllTags(file).toSource()
);
// or call ID3.getTag([file], [tag]) to get a specific tag
alert(
"Title: " + ID3.getTag(file, "title") + " by artist: " + ID3.getTag(file, "artist")
);
}
ID3.loadTags(file, mycallback);
The first method, (getAllTags) doesn't allow my script to run, and the second method returns null for both title and artist on all of my mp3's.
Source of Info: http://blog.nihilogic.dk/2008/08/reading-id3-tags-with-javascript.html
I know these methods are using ID3(v1), so that may be the problem. Either that, or I suppose it's possible by mp3's don't contain ID3 information. But if anyone could provide some insight into how to do this, or how to identify if my mp3's contain ID3 info and whether it's v1 or v2 would be great.
Edit: I should say, I'm accessing the files via Blob URL's because the app that I'm developing let's the user select a directory on their computer and then queries the files for media files. In doing this, you can't access the absolute path of the file, but you still can access the file information and use the file.
For others to use: this worked quite well for me :)
github.com/aadsm/JavaScript-ID3-Reader/tree/master/src use the project repository
I'm using jquery to rewrite a list of links on the page. If the location.host is NOT the vendor location.host AND the cookie isn't set to a specific value then it locates the links and rewrites them to the alternate values. The code I'm using works great in FF but not in IE7. Please help!
<script type="text/javascript">
// link hider
var hostadd = location.host;
var vendor = '172.29.132.34';
var localaccess = 'internal.na.internal.com';
var unlock = 'http://internal.na.internal.com/Learning/Customer_Care/navigation/newhire.html';
// link rewriter
$(document).ready (
function style_switcher(){
//if not a vendor or not accessing from lms reroute user to lms
if (hostadd != vendor && $.cookie("unlockCookie") != unlock){
var linkData = {
"https://www.somesite.com": "https://internalsite.com/something",'../Compliance/something/index.html':'../somethingelse.html'
};
$("a").each(function() {
var link = this.getAttribute("href"); // use getAttribute to get what was actualy in the page, perhaps not fully qualified
if (linkData[link]) {
this.href = linkData[link];
}
});
}
});
</script>
What you could do, if you insert the links dynamic, is store them in a data attribute like data-orglink="yourlink" which wouldnt be transformed by the browser, then check on that -and if its in the object array - change the href. Do you have access to creating the data attribute?
IE7 have problems with internal links, because it puts the host info on, before JS can reach the link..
http://jsfiddle.net/Cvj8C/9/
Will work in all, but IE7. So you need to use full paths if to use JS for this function :(
You had some errors in your JS.
But it seems to work fine?
See: http://jsfiddle.net/s4XmP/
or am i missing something? :)