HTML Url Request Parameter - html

I have a local test-page. The URL is:
file:///C:/Users/User/Desktop/HTML/TEST/URLREST/Test.html
I only want to change the URL in
file:///C:/Users/User/Desktop/HTML/TEST/URLREST/Test.html?id=2
or something like that. Just a different URL.
How i can manage that?
I wrote this site in html.

With javascript
<script type="text/javascript>
window.location.href = 'file:///C:/Users/User/Desktop/HTML/TEST/URLREST/Test.html?id=2';
</script>

Related

Redirect URL using?

Is there any way to redirect a URL by having 1 centeral redirect page like:
example.com/redirect
and having a sort of attribute at the end to redirect to a certain page,
example.com/redirect?pagename
and in the code it will tell the webpage to redirect to the desired page.
Sorry if I baffled or anything I'm quite new to this sorta stuff.
That is possible if you can have a CGI script, FastCGI program, or PHP script behind that URL. It can then look at the parameter and dynamically create a reply page with HTML redirect in the header.
You can by adding in your redirect page or
javascript:
<script>
window.location = "http://google.com";
</script>
or
PHP:
<?php
header("Location:http://google.com")
?>

How to externalize json-ld and include in html doc

Is it possible to externalize json-ld and include it in an html document like this:
<script type="text/javascript" src="http://www.example.com/data123.jsonld"></script>
There doesn't seem to be any documentation about this online....
You can't do that. You should get the json with an AJAX request.
You can do it easy with jQuery
JS
$(function(){
$.getJSON("data123.jsonld", function(data) {
$('.json').text(data);
});
});
HTML
<div class="json"></div>
If your json file is not in your file system (cross domain) you should try something like this.

How to redirect from a domain to another keeping the path component?

I wish to redirect a page from a domain (properly a subdomain) to another maintaining the same path component.
I'm using a blogging service, not running a server; but I can edit the global head of my blog.
I've managed to redirect towards the main page of the other site using:
<meta http-equiv="refresh" content="1; url=http://subdomain-2.domain.com">
<script type="text/javascript">
window.location.href = "http://subdomain-2.domain.com"
</script>
But I'm not able to redirect any page of the first domain towards the corresponding one of the second — say, http://subdomain-1.example.com/post/lorem-ipsum-123 to http://subdomain-2.example.com/post/lorem-ipsum-123.
I'm wondering if it's possible to grab the current URL and substitute the target domain to the original just by editing the head.
I suppose I can only use HTML, JavaScript or PHP.
Solved using JavaScript as follows:
<script type="text/javascript">
window.location.href = "http://" + "here-your-target-domain" + window.location.pathname
</script>
The key element was window.location.pathname. Here I've found what I needed.
The easiest way to redirect to a different domain is to directly set the hostname (not host) part of the URL like this:
<script>
window.location.hostname = 'subdomain-2.example.com'
</script>
This will redirect you to the same URL (including protocol, port, query string, hash) but with the domain replaced.
Here is a nice visualization to understand all properties on the location object: https://developer.mozilla.org/en-US/docs/Web/API/Location#location_anatomy

Change name of download in javascript

If a user clicks on a downloadable link such as
Download
Is there a client-side (html or javascript) way to change the name of the file before the 'Save As' dialog?
HTML5 provides the a[download] attribute which lets you rename a file. This example will download link.txt and rename it something.txt.
​<a download="something.txt" href="link.txt">asdf</a>​​​​​​​​​​​​​​​​​​​​​​​​​​​
Note that this only works on same-origin URLs (i.e. not across different domains).
No, you cannot change this from the client side (HTML or javascript). You need to change it from the server. One way is to use a server side script which will set the Content-Disposition HTTP response header:
Content-Disposition: attachment; filename=somecustomname.txt
You can use Filesaver.js script written by eligrey(Im using angularjs in the example here)
You can achieve the same in classic javascript using XmlHttpRequest object
//In your html code , add these : ->
<script src="https://rawgit.com/eligrey/FileSaver.js/master/FileSaver.js" type="text/javascript"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular-animate.js"></script>
//In your Javascript:-
$http({
url: "url where the file is located",
method: "GET",
responseType: "blob"
}).then(function (response) {
saveAs(response.data,"newfilename.extension");
})

$ is undefined (JSON)

I'm trying to use JSON for the first and I use the code:
var url = 'http://where.yahooapis.com/geocode?q=Vancouver&flags=J&count=10&lang=en&appid=' + myAppId + '&callback=?';
$.getJSON(url, function(data){
console.dir(data);
});
but I get on IE8 the error :
'$' is undefined
what am I doing wrong?
thanks.
Looks like you are trying to use jQuery and the script include is missing.
Include the URL for jQuery.js before using the $.
Try to place something like:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
before the getJSON
$ is provided by a couple JavaScript libraries, the most common of which is jQuery.
If you're not including jQuery in your page, that's likely your issue.
Looks like you're not including JQuery before making this call?
the $ symbol is used by JQuery. Do you have the script for jquery included in the web app before you are using it ?
add this at the top of the offending page.
<script src="{Change this to the path to your jquery.js file}"></script>