Safari nextjs redirect drops hash and query on prod build - hash

Using something as simple as <a href={url + '/#some-hash'} />.
By going to url in href hash or even query parameters by Safari get lost.
If I use router.push or Link from next/link instead, hash is still there, but page is loaded twice. First time without hash and second with.
There is an assumption that it tries to render it client side first and after that makes it server side. But how can I prevent double rendering? It makes two records in history.

Related

In ColdFusion, how to I remove the text at the end of my URL?

Sometimes, links open pages in my website with weird text at the end of it (like Facebook). I would like to remove that text, since my page will not display with it there.
For example, what I would like to do is tell my page that if the URL has text after a pound sign, remove it and open the URL without it.
So if someone opens my page with:
http://www.example.com/news/stories/this-is-a-news-story/#sthash.MmwTdqVa.dpuf
I want it to correct and open the page
http://www.example.com/news/stories/this-is-a-news-story/
How would I do that? I know how to do this with PHP, but I'm new to ColdFusion.
Thanks!
Brendan
Are you using a service like AddThis.com? If so, these (and other) marketing services may add fragment to URLs for tracking purposes. They're harmless, but here's AddThis instructions on how to remove them if you use their service. (Check w/your marketing team before you do this.)
http://www.addthis.com/academy/removing-hashtags-anchors-and-tracking-codes-from-your-urls/
The fragment is not passed to the ColdFusion server and not in the CGI scope. It's intended to be available and used in the client browser only. This should not be causing any problems with "ColdFusion" generating pages, so your problem may due to javascript. Open up Web Developer tools (F12) to identify any javascript errors that may be caused by the unexpected fragment. (You didn't provide a URL or error message, so it's difficult to troubleshoot the problem you may be encountering.)
Here's an existing solution on StackOverflow that you could you use to remove the fragment client-side:
https://stackoverflow.com/a/13824103/693068
// remove fragment as much as it can go without adding an entry in browser history:
window.location.replace("#");
// slice off the remaining '#' in HTML5:
if (typeof window.history.replaceState == 'function') {
history.replaceState({}, '', window.location.href.slice(0, -1));
}
I would only advise performing this once during pageload and maybe include a filter to preserve any fragments you actually want to preserve.
As a side note, I occasionally add Go to Top to long pages without any matching #top element. Normally any id that is not found will force the browser to automatically scroll to the top.

urlread pound sign (#) doesn't work

Trying to read in the pricing lists under pricing information tab:
urlread( ' http://www.cefconnect.com/Details/Summary.aspx?Ticker=KYE#pricing ' )
But in url '#pricing' doesn't help.
Any suggestions?
As already pointed out by Darin, it's no use adding #pricing to the URL. The web page uses client-side techniques to switch between tabs; not something that can be used by urlread.
Summary.aspx always returns all tabs together as one big page. CSS and JavaScript make it look like a collection of tabs, when opened in a web browser.
Use the developer toolbar of your web browser to inspect the web page. For example in Google Chrome, just right-click on the section you are interested in, and select 'inspect element'.
I don't know what you are going to do with the result of urlread, but you'll probably have to do some parsing to distill the information you need from the HTML clutter.
Please note Summary.aspx launches additional HTTP requests to retrieve additional data. Use the 'Network' tab of Chrome's developer toolbar to analyze that behavior. For example, the following request is made when you click 'GO' after adjusting the pricing history filter criteria.
http://www.cefconnect.com/Resources/TableData/?Type=PricingHistory&Cusip=48660P104&param0=1M&param1=06/06/2014
At first, this seems to complicate the whole matter, but it may actually be a great opportunity. You can call urlread with the URL above, and get some data in JSON format, which is far less cluttered than HTML. Adjust the parameters to get different data. I'm not sure what 48660P104 is; it might be an internal representation of KYE. You may want to use an initial HTTP request to Summary.aspx to retrieve that code; you'll notice the webpage is littered with URLs containing the same parameter Cusip.
The # character has a special meaning in an url. It represents the fragment identifier and the value following it is never sent to the server. Only client side javascript can access it. You will need to url encode the value if you want to send it to the server:
urlread( ' http://www.cefconnect.com/Details/Summary.aspx?Ticker=KYE%23pricing ' )
This also stands true for other special characters. You need to properly encode them.

Why does GET pre-fill data trump POST data, and is there a simple way to reverse this?

In my mod_perl2 app, on one page I link to with ?form_field_name=pre_fill_value tacked onto the URI if I want to pre-fill a particular form field for the user. However, the form itself is just <form method=post>, which posts back to the current page, GET query and all. I expected that Apache2::Request's param() routine would serve up either only the POST data, or the POST data first. Instead, it seems the GET data is given precedence, i.e., the prefill is honoured over the manually-user-fixed data.
The easy fix is to add action= and the current URI without the GET query, but I'm wondering why it was designed this way, and if there's a sneaky way around it, like some mod_perl2 option that would give POST data precedence. However, the easy fix can actually cause problems if un-overridden GET query values are expected to be passed on. So this workaround quickly grows, but why is it even this way in the first place?

Facebook Like Button with hash

when i try to add to my website a FB Like Button with url+hash (example.com/#TEST)
and i try to click the like button - it shares the link without the hash in the news feed (example.com).
when i try to setup the button with "%23" instand of "#" (example.com/%23TEST) - it counts each hash separately in the count box.
is there any way to put a like button with hash - and still count the url without the hash?
Thanks!
When you are creating Facebook like buttons, Facebook uses cURL (correct me people) to acces your URL that has metadata. So if cURL sees different metadata, per URL, you will get different LIKE buttons.
But this doesn't happen; as on the server side, Facebook sees the same URL for every dynamic # enabled link. Since the part of the link before # is same. JavaScript (or any Behavior that can create a hash in URL) is ignored, obviously, since its Behaviour is a client only thing.
The best possible way would be to create the Button dynamically using JavaScript and change the URL-to-like of each button to something friendly without hash.
abc.com/def#part1
abc.com/def#part2
// to
abc.com/def/part1
abc.com/def/part2
Only for the curl script to see it as a different URL.
And when the user hits that link - abc.com/def/part1 - you would be needing server side help as well to redirect to the view part1 from the route def. So you would, in your router code, load only upto the route def (imagine MVC) and then ask the controller to load the view part1, with JavaScript enabled to append the URL hash #part1.
These hash tags are for client side actions not server side. You will not be able to use them in your Like Button.

Codeigniter form action with slashes instead of normal GETs?

Hey, so this is one of those questions that seems obvious, and I'm probably going to feel stupid, but here goes:
I'm doing a CodeIgniter site with a search. Think of a Google type input, where you'd search for "white huskies." I have a search results page that takes a URI (MySite.com/dogs/white huskies), and takes the third part, and performs the search on that term. I'd like this to be done in the URI, and no by POST so my users can bookmark results.
The problem I'm having is how to get that search button directed to Mysite.com/dogs/WHATEVER IS IN THE INPUT. How do I get the what is in the input part into the anchor href? I know I could do this with javascript, but I've heard it's bad practice to force people to have javascript for things this small.
Thanks for the help!
Read: Form redirect to URL containing query term? - pure HTML or Django
(asked for Django, but answer fits here too)
You could have an intermediate POST page that collects the form inputs and concatenates them into a valid URL which you can then redirect to. I'm not sure if this is good or bad SEO practice however, but I can't see another way of doing this without some Javascript intervention.
Perhaps you could look at doing the intermediate POST page which takes the values are redirects you to /search/dog/white/huskies, but also have a Javascript equivalent that does this on the fly on the form submit and does a window.location refresh to the same /search/dog/white/huskies?
Just my 2 pennies worth ;)
It is possible to have CodeIgniter work with $_GET variables and URI segments securely.
A work around I have used in the past is to have the search term collected using POST, parse the required URL for use with URI segments and then redirect your user to this page.
$url = 'mysite.com/search/' . urlencode($_POST['query']);
redirect($url);
This shouldn't effect SEO but something like the URL of a search result is unlikely to have any effect on SEO anyway. Clean URLs are only really meant to be used for permanent content. If you're going to be displaying the search term on the page, remember to use xss_clean(), seen a few people make this fatal mistake before.