Is it possible to get requested URL without Javascript - html

I have a page that uses Javascript to load some content.
I would like to forward to another page (But keeping the URL parameters) if the user does not have javascript enabled.
I can use the following to forward
<noscript>
<meta http-equiv="refresh" content="0; url=http://testurl.com" />
</noscript>
But I have to hardcode the URL. Is it possible to retrieve the requested URL (and parameters) without the use of javascript, or server-side code (I dont have access to server code).
I am looking for a non javascript equivalent to "window.location.search", if such a thing exists.

Related

How would I make a meta redirect that redirects to the URL stored in the parameter?

I am attempting to setup a service which will redirect the user to a URL stored in the ?url= parameter, how would I do this?
I have tried using meta
http-equiv="refresh"
with
out.print(request.getParameter("ur;")) %>
however all that happens is the page reloads in a loop. Not too sure if I need to use quotation marks (e.g /?url="https://google.com")
<meta http-equiv="refresh"
content="0; URL="<%
out.print(request.getParameter("redirect")) %>">
What I need to happen is when the user gets redirected to "https://example.com/exampledir/index.html?url=https://anotherwebsite.com" (just an example url) the script on index.html will get the parameter and redirect to it exactly. What actually happens is the page just reloads in a loop.
Since you're not using any server-side language, you won't be able to generate a different meta tag during rendering. Instead, you'll need to do this with JavaScript after the page loads.
Add a script tag to the bottom of the page like this:
<script>
var redirect = new URL(window.location).searchParams.get('redirect');
if (redirect) window.location = redirect;
</script>
Now if you browse to the page like this: http://<myserver>/myfile.html?redirect=https://google.com you'll be redirected to https://google.com.
For reference, see MDN articles on:
Window.location
URL.searchParams
I also highly recommend you read through Java​Script basics just to make sure you understand the overall concepts presented here.

How to pass URL parameters when redirecting to another URL?

I'm using this html code to redirect to another URL when the page (www.dasinfobuch.de/links/Wizz) is invoked:
<head>
<meta http-equiv="refresh" content="0; URL=http://52.28.104.181:8080/Wizard/Wizz">
</head>
However, when I use a URL parameter such as
www.dasinfobuch.de/links/Wizz?template=test
the parameter is not passed on to the redirected page. Is there a way to accomplish this (preferably in plain HTML)? (I'm new to Web programming.)
This is not possible using only a meta element that mimics the non-standard Refresh HTTP header field. Of course there are other ways.
If you’ve got something like a preprocessor, you can pass on the request to the HTML, like so:
<meta http-equiv="refresh"
content="0; URL=http://52.28.104.181:8080/Wizard/Wizz?template=<%
out.print(request.getParameter("template")) %>">
Another (client-side) way is to redirect using JavaScript:
document.location.href = 'http://52.28.104.181:8080/Wizard/Wizz' + document.location.search;
Note that this will carry over the entire query string, not just the template parameter and its argument. If that’s a problem, it’s easy to get only the desired string from location.search.

How do I redirect to the requesting URI using only HTML?

I want to create an html file that I can use as a link that will (eventually) redirect to the requesting URI.
I can hard code the redirect target to be the caller, but I'd rather not.
Update:
As for what I will use to do it, the following comment provides a starting point:
from https://stackoverflow.com/users/665261/billy-moon
on Redirect from an HTML page:
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="1;url=http://example.com">
<script type="text/javascript">
window.location.href = "http://example.com"
</script>
<title>Page Redirection</title>
</head>
<body>
<!-- Note: don't tell people to `click` the link, just tell them that it is a link. -->
If you are not redirected automatically, follow the <a href='http://example.com'>link to example</a>
</body>
</html>
This will not work unless I'm willing to replace the 'http://www.example.com' with my calling page similarly in a hard-coded fashion.
Unless, there is a way to redirect to the calling URI, programmatically.
This will be a client side redirect. I don't have knowledge of the web server that my company uses and it cannot be assumed since this will be placed in production if it works. My html will be static.
Aside:
The goal is to provide a link that once requested calls a third-party API, then redirects to the calling URI. (I do not have connectivity to the third-party API yet, so figuring that out is not part of the question.) Doing something in the interim, after the html has loaded, but prior to the redirect (such as calling the API/making a command-line terminal call against a scheduler) is desired, however.
But to be clear, my question is 'How do I redirect to the calling URI within an html file?'
use the meta tag refresh
see: http://webmaster.iu.edu/tools-and-guides/maintenance/redirect-meta-refresh.phtml
example:
<META http-equiv="refresh" content="0;URL=http://www.example.com">

Razor CSS file location as Variable

I am wrapping a razor view in an iframe. The razor view is a web service on a different domain.
Here is what I am doing:
<!DOCTYPE html>
<html>
<body>
<p align="center">
<img src="http://somewhere.com/images/double2.jpg" />
</p>
<p align="center">
<iframe src="https://secure.somewhereelse.com/MyPortal?CorpID=12334D-4C12-450D-ACB1-7372B9D17C22" width="550" height="600" style="float:middle">
<p>Your browser does not support iframes.</p>
</iframe>
</p>
</body>
</html>
This is the header of the src site:
<!DOCTYPE html>
<html>
<head>
<title>#ViewBag.Title</title>
<link href="#Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<link href="#Url.Content("~/Content/themes/cupertino/jquery-ui-1.8.21.custom.css")" rel="stylesheet" type="text/css" />
<script src="#Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/jquery-ui-1.8.11.min.js")" type="text/javascript"></script>
</head>
I want the iframe src to use the CSS of the calling site.
Is there a way to pass in the CSS URL or have it inherit the CSS of the calling site?
I'd even settle for the css file location being a parameter being passed in from the originating site.
Anyone have any suggestions?
You cannot enforce your css on your site using an iframe. The css must be included in the source of the page included in an iframe. It used to be possible but in certain cases using javascript, and for the page to be on the same domain.
The only other way you may be able to use your own css is if the web service allows you to pass in the url of the css. But you would have to consult the documentation of the web service to find that out.
I would pass the CSS url as an argument to the iframe's src attribute:
<iframe src="http://somedomain.com/?styleUrl=#(ResolveStyleUrl())"></iframe>
Where ResolveStyleUrl might be defined as:
#functions {
public IHtmlString ResolveStyleUrl()
{
string url = Url.Content("~/Content/site.css");
string host = "http" + (Request.IsSecureConnection ? "s" : "") + "//" + Request.Url.Host + url;
return Raw(url);
}
}
This is of course assuming that the domain would accept a style url query string and render the appropriate <link /> on the remote page?
Eroc, I am sorry you cannot enforce your css on others' site using an iframe because most browsers will give an error like the one chrome gives:
Unsafe JavaScript attempt to access frame with URL http://terenceford.com/catalog/index.php? from frame with URL http://www.example.com/example.php. Domains, protocols and ports must match.
But this does not mean that you cannot extract the html from that page (which may be modified as per your ease)
http://php.net/manual/en/book.curl.php can be used for site scrapping with http://simplehtmldom.sourceforge.net/
First play with these functions:
curl_init();
curl_setopt();
curl_exec();
curl_close();
and then parse the html.
After trying yourself, you can look at this example below that I made for parsing beemp3 content, when I wanted to create a rich tool for directly downloading songs, unfortunately I couldn't because of the captcha but it is useful for you
directory structure
C:\wamp\www\try
-- simple_html_dom.php
-- try.php
try.php:
<?php
/*integrate results for dif websites seperately*/
require_once('simple_html_dom.php');
$q='eminem';
$mp3sites=array('http://www.beemp3.com/');
$ch=curl_init("{$mp3sites[0]}index.php?q={$q}&st=all");
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
//curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
$result=curl_exec($ch);
curl_close($ch);
$html=str_get_html("{$result}");
$ret = $html->find("a");
echo "<head><style type='text/css'>a:link,a{font-size:16px;font-weight:bold;font-family:helvetica;text-decoration:none;color:#458;}a:hover{color:#67b;text-decoration:underline;}a:visited{color:silver;}</style></head>";
$unik=array(null);
foreach($ret as $link)
{
$find="/(.{1,})(\.php)[?](file=.{1,})&song=(.{1,})/i";
$replace="$4";
if(preg_match("{$find}",$link->href))
{
$unik[]=$link->href;
if(current($unik)===prev($unik)){unset($unik);}
else{
echo "<a href='".$mp3sites[0].$link->href."'>".urldecode(preg_replace($find,$replace,$mp3sites[0].$link->href))."</a><br/>";
}}
}
?>
I know that you do not code in php, but I think you are capable of translating the code. Look at this:
php to C# converter
I spent time on this question because only I can understand what it means to offer bounty.
May be the answer seems unrelated (because I have not used javascript or html based solution), but because of cross-domain issues this is an important lesson for you. I hope that you find similar libraries in c#. Best of luck
The only way I know to achieve that is to make the HTTP request on your server side, fetch the result and hand it back to the user.
A minima, you'll need either to strip completely the header from the targeted site to inject the content in your page using AJAX, or to inject your own css in the page headers to put it into an IFRAME.
Either way you have to implement the proxy method, which will take the targetted URL as an argument.
This technique has many downsides :
You have to do the queries on you server, which can cost a lot of bandwidth and CPU
You have to implement the proxy
You cannot transmit the domain specific cookies from the user, though you can manage new cookies have by rewriting them
If you do a lot of requests you server(s) is/are likely to become blacklisted on the targeted website(s)
The benefits sound low compared to the hassles.

Does the Meta Refresh tag (zero delay) wait for page to finish loading?

Does the Meta Refresh tag (with a delay of 0) wait for all components of page to load \ all scripts to finish executing before performing redirect?
I have the following page tag in the HTML document's head:
<meta http-equiv="refresh" content="0;url=http://example.com/">
the HTML document contains other stuff such as script tags linking to remote Javascript (e.g. Google Analytics), and Javascript code that performs AJAX request.
Can I count on everything to get run? Or may the browser cancel downloading scripts \ performing AJAX \ running scripts mid-way due to a redirect?
(am aware of the option of implementing with Javascript instead of Meta tag, would like to know about Meta tag)
"Can I count on everything to get run?" - No
It is context dependent, i.e how the page is composed and which user agent you are talking about. It's not fool proof.
Why not do the redirect server-side using Response.Redirect (.NET) or header("Location:"); (PHP)?