Is it possible to put several URL in a href parameter? - html

I want to put a link with the <a> tag on my website page, but with multiple URLs in case the 1st one doesn't work. I would be something like this:
<a href="url1;url2;url3"
But of course this doesn't work. So is there a way to do this ?
Thank you

The closest you could come would be to:
Put a default URL in the href
List alternative URLs elsewhere (such as in a data attribute)
Bind a click event handler that runs some JavaScript which prevents the default behaviour and then tests each URL in turn until it finds one that works (or runs out).
Testing would require Ajax which would require either:
Permission via CORS from each URL you test
The user of a proxy (which would test availability of the URL to your proxy and not to the browser)
The additional HTTP requests would consume bandwidth (and thus time).

What do you mean by "1st one doesn't work" ? That the server is sending an error ?
It's not possible to do what you want just with HTML.
It could be done by Javascript by adding a listener to the anchor, sending HTTP request on the first url to see if you receive 200 or an error like 500.
In case of an error, you check the second url and so on and redirect the user where you received a 200.
Otherwise, if you just want to open all the links, there was already a post about that here: How can I open multiple links using a single anchor tag

There's no way of doing this with pure HTML since HTML can't detect whether or not what you mean by "doesn't work" applies to a given URL.

Related

Does html structure make difference in get or post request?

I have a href , when i click on it, it goes with "POST"request.
(PS. i am using magento 1 framework)
<li>
Logout
</li>
when i remove this "login-popup-in-footer my-account-text" it goes with GET request which is ideal.
I am not sure if HTML Or htaccess file makes difference in GET OR POST request.
Feel free to share thoughts.
Thankyou
Neither, at least not directly.
The HTML you have will trigger a GET request. It can't do anything else.
It will be some client-side JS that is searching the document for elements which are members of one or more of those classes and adding an event listener that prevents the default behaviour of the link and makes a POST request.
Your server configuration can't influence it either. While it could issue a redirect response there is no way for one of those to response to a GET request in a way that causes the browser to make a POST request (although the reverse is not true).

How to force load href that uses same URL but different hash params

Say that my navbar has these two URLs:
<a href='/action#?action_type=test'>test</a>
and
<a href='/action#?action_type=tset'>tset</a>
My problem is, say that you're in the 'test' page, if you click on the tset page it will just change the hash params and not force a load. The reason why I'm not using onclick listeners instead is because I want to let the user be able to ctrl + click on an element if they want it in a new tab. If I use onclick listeners that feature seems to go away. How should I proceed about this?
A hash param is actually called a fragment url.
Fragment urls aren't sent to the server (see other question), instead, they are supposed to be used to link to different parts of a page (using anchors). You shouldn't reload the page when you click on one, and browsers don't expect you too.
If you need to reload when you click a hash fragment, you're doing something wrong.
Instead, try using a query parameter instead, this will automatically reload from the server, and lets the browser know what you're doing.
<a href='/action?action_type=tset'>tset</a>
HTML requires you and the browser to agree on what you're doing. You could trick it with Javascript, but then you're losing support from the browser.
Either decide if you want to use Javascript, or decide to use query strings.

How do I auto-fill in this textbox at the US govt website via the URL?

I'm trying to embed a value into the textbox at the USCIS government website to check my application status number. Suppose it's LIN1234. After inspecting the element of the webpage I see that the HTML wrapper for the textbox is:
<input id="receipt_number" name="appReceiptNum" class="form-control textbox initial-focus" maxlength="13" type="text">
I tried opening up this URL with a suffix added on, but to no avail:
https://egov.uscis.gov/casestatus/landing.do?receipt_num=LIN1234
Is there a way to to this?
Before that, you must understand what means adding ?receipt_num=LIN1234 to the url.
When sending a request (By default and in this context) from your browser, it'll be a GET request (see here) where you send as a get argument your receipt number, setting its key to receipt_num.
What is done to this data on the server side, however, is up to itself.
Just understand that unless the server is made to auto-fill the field with that value in case it receives it, it won't do anything except sending some more data.
I think you want to load this page in your browser with auto-filled field.
In that case you should look into extensions for your browser that would do that automatically.
You probably won't be able to embed a value into the textbox... Just because you are sending values by GET (which is what the landing.do?receipt_num=LIN1234 syntax is doing) doesn't mean that they have something set up to process it, so the GET variable will probably not do anything.
You might be able to see how their URLs work ordinarily, what the page URL that you are aiming to land on looks like, and either decode something from that or set a bookmark there. That said, if they are submitting that data via POST (which they probably are, for security reasons), that probably won't work.
I would suggest looking at reputable form-filling plugins for your web browser, if that's an option. That might allow you to work around that.

Refering an Html URL in the src attribute of img tag

This could be a trivial question. But has some doubts in the below scenario.
I have a master logout, and this master logout has to call multiple individual logout pages.
These individual logout pages has to be called in the background.
Some of the individual logout pages can redirect to master logout (very rare, could be due to a programming mistake). But just want to consider it as failure scenario.
To achieve this,
a. I added hidden img tags to MasterLogout.html
b. And src attribute of each of this img tag is pointing to teh logout pages, say img tag's src is src="http://testapp1.abc.com/logout.html"
say img tag's src is src="http://testapp2.abc.com/logout.aspx"
c.Based on my observation form HTTP header trace, logout URL's in src tag are being called, and I see some response codes 200, 302 etc.,
d. Also the logout functionalities is working well.
However I have the below doubts, need inputs on below.
Q1. How does img tag behave when its src is pointed to any html etc other than img. Does throw an error to browser? Can it cause any rendering issues to UI in any browseres etc ( IR, firefox, chrome didnt show any issues in my observations so far).
Q2. when the individual logout page gives a response of 302, is this reidrect reponse followed by the browser? ( I didnt see any redirections are HTTP trace, but want to know about the behaviour in diff browsers or any special cases that could cause an issue here
Thanks,
Malli.
Q1: Img tags can have an src pointing at whatever, the browser makes a request, and tries to render the response as an image, if it fails it will show the broken image icon and/or the alt text, but if the image is hidden it's not gonna render it anyway, neither it will throw any other error.
Q2: 302 responses are being handled on HTTP level, thus yes, the browser will follow the redirect, regardless if it's in an img src or elsewhere, but in your use case it will not cause any issue.
use data-* attributes with javascript or jquery
get data attributes in JavaScript code

Is there a URL parameter that will make the URL open in a specifically named browser window

I have an email digest that is sent daily to users of my website and contains links to things on the site so that they can easily get right in and start interacting from their email. Trouble is, if they click more than one link, they're going to be opening more than one browser and the non-technical user might not catch that and end up having to close a bunch of tabs/browsers when they're done on the site. I want all the links in the email digest to be opened in the same window/tab.
I know that if you have an href you can set target=my_window and the links will open in that window. I'm wondering if there's a URL parameter that can be used instead of editing the a tag.
No. I don’t know of any browser (or other user agent) that associates any special behaviours with link query strings. The query string is for the server receiving the HTTP request to deal with.
As you say in your question, the target attribute is the method for controlling (or at least suggesting) what window the link should open in.
Can you use the window.open method?
Reference: window.open(url, name, features, replace);
It allows a browser window to be named, and thus reused when clicking on new links that are formatted to work with the window.open syntax.
Example: link
Status Update: Note you can search for many window.open(); Online Generators to help build the look of the opened window. It's important to test the desired look in all browsers, as the Address Bar in each browser is rendered differently.
The short answer is no. This behavior you are talking about is strictly client side, controlled by the browser. The application running on the web server is responsible for reacting to the query string.
Do you not have control over the template of the e-mails that are sent? It should be trivial to add the target to the appropriate anchors.
You can use PHP to catch custom URL parameters.
Say you have a link like:
www.yoursite.com/somepage.php?title=Some Page Title Here
The paramater string in the URL starts with ?something=somevalue and can be chained with the & symbol (e.g. ?something=somevalue&somethingelse=someothervalue) etc.
You can then ad this PHP to the top of your page:
<?php $title = $_GET['title']; ?>
Then for your title tag put the following:
<title><?php echo $title; ?></title>
You would add another variable with the value of the param for each param you want to pass in to the page. But for what you're trying to do, the above code will work.