Hiding the domain of a HTML page in address bar - javascript

Suppose you open an HTML page on web it has url like :
https://storage.googleapis.com/fasdcjh-jdfsdf/ga/123/test.html
I want to put some javascript in test.html so that the url changes to
lkasdjhfklahsdfklasjdflahfd (some random string)
The test.html is my creation so i can modify it to achieve it.
what i tried :
Insert this script in the html
<script type="text/javascript">
window.history.replaceState(null,'title','asdakjsdhjkad');
</script>
It changed the url to - https://storage.googleapis.com/fasdcjh-jdfsdf/asdakjsdhjk
So the last part did got changed. But the domain storage.googleapis.com and the rest of the string in path didnt.
How to achieve that ?
PS:
The HTML files will be uploaded to a google cloud storage account.
The above script worked when accessing the document from the google cloud storage but only hiding the last part

Related

Can I load a web path from an external file

I have an application thats uses HTML5 and there are many html pages that point to the same url, however, the url can change.
Is there a way that rather than pointing each individual html page to a url, that i can point them to a single file that contains a url, therefore only having to change the url from one location and individually?
I.E. 10 pages contain an iframe with src="http://www.google.co.uk" if I now wanted them to point to "http://www.yahoo.co.uk" I'd have to make that change 10 times instead of once. Could i create some kind of file so that src="webpath" instead?
You can use an external javascript file which will be used in all the ten pages and you , just, can edit the javascript file to load the same iframe in all the ten pages.
All the 10 pages:
<script src="iframe-location.js"></script>
<body onload="loadIframe()">
<iframe id="frame"></iframe>
</body>
iframe-location.js (External js file):
//You just can change the iframe src
function loadIframe() {
document.getElementById("frame").src = "https://bing.com";
}
You can use redirection using javascript
Create a resource that will be used by the 10 pages and that page will have the redirection
window.location.replace("http://www.yahoo.com");

Insert script at login page - Roundcube

I'm trying to insert that Mcafee Security etiquette into my web page. Mcafee gave me the following code:
<script type="text/javascript" src="https://cdn.ywxi.net/js/1.js" async> </script>
However, it does not appear on my page when I add it.
I'm adding in the <head> tag. The page to which I am inserting is in the following location:
/home/apache2/old/newmail/skins/george
Login.html
You need to make sure the website you are trying to insert it on is registered and currently being used. The script looks at the location.host, here would be stackoverflow.combefore sending the code to display the actual element. Note the line with setting the src attribute.
try{
var v=document.createElement("script");
v.setAttribute("type","text/javascript");
v.setAttribute("src","//cdn.ywxi.net/js/host-loader.js?h="+location.host);
document.getElementsByTagName("head")[0].appendChild(v)
}catch(e){};
You can test this by going to the website cdn.ywxi.net/js/host-loader.js?h=<YOUR HOST HERE> and confirm there is JavaScript sent back.
You need to put the code into
/usr/share/apache2/roundcubemail-1.0.1/skins/larry/includes/links.html

Add query string to script tag link in asp.net to break Cache

Hope someone can help me on this. I manage an ASP.Net website and usually update script files and css files very often. I add current time appended into a single string as a query string parameter (eg: profileImage.jpg?123021) which makes the browser to look for the file without getting it from cache.
How can I do the same thing to all script tags and css links from the server side so that it loads the latest version of the file.
Any help appreciated.
Amila
If your asp.net website uses Master Pages, it should be easy to make these changes in the Master Page file. Look a file with the extension .master. If you are not sure how to make the specific edit, post the <head> area from the master page markup in a new question.
MSDN Master Pages: http://msdn.microsoft.com/en-us/library/wtxbf3hh(v=vs.100).aspx
If your site does not use master pages, then you'd need to create some server-side logic that affects the <head> section of the page. Below are some links to related QA's about injecting script and styles from the server side.
ASP.NET: How to (programmatically) attach a <script> tag, containing a link to .js, to <head>?
How to Add script codes before the </body> tag ASP.NET

How to access the data-directory in HTML

In the "Simple Addon"-tutorial of the Mozilla Addon-SDK, it reads:
/data - contains resources such as icons or HTML files, as well as
any content scripts included with your add-on. You can access the
content of the data subdirectory from within your add-on's code using
the Add-on SDK's self module.
In my Add-On, I use a HTML-page to display some contents in a panel. Since the contents are loaded by a Content-Script, i want to display a spinner.gif-file on the HTML-Page to show the user that the contents are being loaded. After the contents are fully loaded, I hide the spinner-image and display the contents (using jQuery).
My problem now is, that i don't have any clue how to embed the image in the HTML-page. The problem I'm facing is that I don't know the path to the image-file.
I know you use the self-module in an AddOn-Script to access the /data-directory, but on how to do this from a plain HTML-file or a Content-Script is not mentioned in the docs.
So this is what I have in my HTML-File (there is no need for the <head>-tag):
<html>
<h2>StackExchange Statistics</h2>
<div id="loading">
<img src="spinner.gif" alt="loading...">
<p>Fetching Data, please stand by</p>
</div>
<ul id="infos" style="display: none">
</ul>
</html>
Both this HTML-page and the image (spinner.gif) are located in the root of the /data-directory, but the above code only shows the alt-text. I also tried using /data/spinner.gif as the source, no luck.
So, how do I load an image from the /data-directory?
I tried reproducing your issue. I've created a trivial add-on and added a script file with the following code to the /lib directory:
const data = require("self").data;
var tabs = require("tabs");
tabs.open(data.url("test.html"));
Now the add-on will open a tab immediately after being installed. I created a file /data/test.html with the source code from your question and an image file /data/spinner.gif. And after the installation of the add-on a new tab opens and the image is there - beautiful. Note that the URL of the tab is resource://something-related-to-add-on-id-data/test.html and the URL of the image is resource://something-related-to-add-on-id-data/spinner.gif which is why the relative URL works. A URL like /data/spinner.gif wouldn't work, there is no data directory after the add-on has been compiled.
Now I guess that you are asking how you would find this URL from a content script? Fact is, the content script itself doesn't have the necessary API for that. But it can receive messages from your add-on. See "Communicating With Content Scripts" section in the documentation. Your content script needs to declare a function onMessage and the onAttach function in the add-on needs to actually send this message. Message payload can be this one URL or some more complicated data structure if you want to transfer more data.
As to regular web pages (not belonging to the add-on): all they can do is "guessing" the URL. You know what URL /data/spinner.gif is mapped to for your add-on. So you can simply use that URL in a web page. The catch: the URL might change in future SDK versions.
The data folder is available in main.js and you can pass that url as a content script option.
To preview the url in the console from main.js:
var data = require("sdk/self").data;
console.log(data.url('spinner.gif'));
To pass the url to the content script in main.js:
var image_url = data.url('spinner.gif');
contentScriptFile: data.url('myScript.js'),
contentScriptOptions: {"image_url" : image_url}
To view the url from the content script:
alert(self.options.image_url);
Let me know if that works for you.

How to get Flash SWF Url using javascript?

How to get SWF url form a webpage using javascript. Actually I want to retrieve all SWF from a webpage, So I wrote an Greasemonkey Script that scans OBJECT, EMBED etc tags to get the swf url. My script works fine on most of the pages, but fails on this one http://www.elkspel.nl/spelletjes/Film+And+TV+spelletjes/Eva+Mendes+Opmaken.html this page is not having any Object, Embed tag in its source and my script fails here.
Is there any way to get SWF Url from any webpage??
In this case, the object tag is embedded into the page loaded into the iFrame. To get the SWF url manually, just grab the url of the page in the iFrame and open it in a browser. Automating that might be difficult though. You would have to do the same thing via code - grab the url from the iFrame and load the page.
You could also look through the Firebug /Net/Flash/ tab and grab the URLs for any SWFs there.

Categories

Resources