Jump to part of page through URL - url

Consider the following link:
https://bittrex.com/Market/Index?MarketName=USDT-neo
I need to somehow manipulate the URL so that when it's clicked, it jumps straight to the Order Book section of the webpage.
I've tried finding the ID for that part and appending it the URL, but that wouldn't work because the ID isn't generated when you enter the page through the normal URL.
Does anyone know how to manipulate the link so it jumps straight to the Order Book part?
To be clear, I do not want to use JS. I want to have a pure link which I can click and will take me to the Order Book.
I need this so I could take a screenshot of the chart using a node module called Pageres.
If anyone has any different idea as of how to download the chart of the Order Book to a png, it'd be awesome (Or even more generally, download a chart of any cryptocurrency's Order Book to a png, using any website).
Many thanks,
~Yuval

Using javascript, you can handle the click in the following way:
<a id="fake_link" class="fake-link" href="https://bittrex.com/Market/Index?MarketName=USDT-neo">Click me</a>
<script>
var elem = document.getElamentById("fake_link");
elem.addEventListener("click",function(e){
e.stopPropagation();
e.preventDefault();
window.location = "YOUR NEW LOCATION";
},false);
</script>

In the general case, all you need is add the id of the part of the page that you want to go to. The section you mention starts with:
<div class="row" id="rowTable">
So all you have to do is add #rowTable to your URL:
https://bittrex.com/Market/Index?MarketName=USDT-neo#rowTable
That will instruct the browser to look for the part of the page with the id that you mention.
But you are right, the id part of the page is generated after it is loaded. In your case it only works if you change the URL with the page already loaded.
You could try using an intermediate page with a bit of javascript that will first load the page, then jump to the part you want.

You can use the location.hash property in java script to grab the hash of the current page
use is like this:
var hash = window.location.hash;
if(hash == "#tabChartOrderBook"){
//function to switch tab
}
I wrote this for your url
https://bittrex.com/Market/Index?MarketName=USDT-neo#tabChartOrderBook
and as I said in code your url hash is #tabChartOrderBook

Related

Rails 3: Creating a unique URL for a view with a unique Partial rendered

The best example I can find of this is the URL of a google images page with a particular image selected. The URL changes for each image that is selected.
In my case, I have a Notebooks model and a nested Notes model. In the view showing all the notes, when the user clicks a note he/she is taken to the Note show view. Instead, I would like them to be shown a partial within the same view, but I'd like the URL to change to include info about the selected note.
How do I do this?
You can do this with replaceState() in javascript. When the user clicks on the notes you open the note any way you want (using an ajax call for instance) and then when it's open you use a callback to fire the replaceState() function that will replace the current url with whatever you want (I suppose the url of your note).
Then, when a user comes into you site with this precise url you can parse the url to show the note he requested (or let Rails default behaviour redirect him to your note show view).
Here is the documentation for replaceState(): https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history#The_replaceState().C2.A0method
Here is a non working example of the corresponding view using jquery to illustrate my point:
= link_to "note", note_path(#note), id: 'x_link'
<script>
$('#x_link').click(function(e) {
e.preventDefault() //we do not let the event propagate
href = $(this).attr('href') //we get the href attribute of our note
$.get(href, function(data) {
show_partial(data) // write some method to display you partial
history.replaceState(null, null, href) //replace the current state
})
})
</script>

Google+ Share specific article

I have included the Google+ share url in my website (not the +1). However, it shares the entire page and not the specific article I want to link to. My article title has an anchor id, but when I add it to the share's url, it doesn't pick it up...
The logo of the page and a short description shows up, but it won't link to the specific article.
Any help would be greatly appreciated!
As far as I know, Google+ share button currently works only for whole pages and not sections.
The only way, though not very user friendly, is to split each content into single pages.
Anyone - pls correct me if I am wrong.
You will need to use the share button rather than the share URL to be able to share links with anchors. Even URL encoding the anchors results in them being stripped from the URL that is shared with the link. When using the button, specify the href value to include the particular anchor that you need.
Another approach if share link is a requirement....
Would be to implement on your site an alternate method for the anchors. For example, use http://mysite.com/?article=myarticleid where myarticleid is the same as the anchor and check for that on page load (source).
function getParameter(param) {
var val = document.URL;
var url = val.substr(val.indexOf(param))
var n=url.replace(param+"=","");
alert(n);
}
var anchor;
function checkForAnchor(){
anchor = getParameter("myarticle");
// Do something with anchor, see code examples below.
}
window.onload = checkForAnchor;
Then add some JavaScript at the end of that checkForAnchor() function that will scroll the page on load to the correct location or just jump to the anchor.
In jQuery, you might animate that effect like (source):
jQuery('html,body').animate({scrollTop: jQuery('#' + anchor).offset()}, 1000);
In standard JavaScript, you could simply change the location and append the anchor:
window.location = '#'+id;

HTML Links that do nothing when you are on the page they link to

I am currently building a website containing lots of links to different sections of my website (also known as navigation). Lets call those links and their corresponding pages link1, page1 , link2, page2, link3, page3 etc.
The general code for them is this:
Link1
Link2
Link3
I want the user to click each link to move to the corresponding webpage and it works as supposed to. The problem is that I want the links to do nothing when the user is on the same page as the link they clicked (meaning it will only reload the page). Let me make this clear by using an example:
Current use: User is on page1. User clicks on link1. The browser will reload page1.
Desired use: User is on page1. User clicks on link1. The browser will do nothing.
TL;DR Essentially I am searching for an if clause. I have read there is no if clause in HTML simply because it's a markup language but what is another way to implement this? Thanks for your help.
The best answer I have found without the need to use JQuery or JS after munching through SO is this, answer made by Matt Crinklaw-Vogt:
Add a /#!. This will prevent the scrolling to the top and will also prevent the page reloading.
Code:
Link1
Original answer:
How do I stop a web page from scrolling to the top when a link is clicked that triggers JavaScript?
I'm not sure I like it, but you could use an empty bookmark to do this...
Link1
If you aren't on page1, it will load page1, but once you are there, it won't do anything.
Link2
OR
<a onclick = "return false;">Link2</a>
That cancels out the load.
On page load, you could use JS as follows
Link1
JS:
document.getElementById("link1").setAttribute("href", "#");
You can use javascript to compare the current url to the anchor link, and if they're the same, prevent the default click event. Using jquery:
var url = window.location.pathname,
urlRegExp = new RegExp(url.replace(/\/$/,'') + "$");
$('a').each(function(){
if(urlRegExp.test(this.href.replace(/\/$/,''))) {
$(this).click(function(event) {
event.preventDefault();
});
}
});

In a Rails app, how can I make a link load in a div as opposed to refreshing the whole page?

I'm still a beginner at web development. It's not my profession. So go easy.
I started building a rails app today, and realized it would make my application so much better if I could get certain links to display in a separate div instead of a new page, or refreshing the entire page. I'm not quite sure how to search for this, and I keep chasing red herrings with google.
Basically, I have a list in a div on the left side of the page, and when one item from that list is clicked, it should appear in the right div. (Nothing else on the page need be changed)
That's really as simple as it is. Do I need to use Javascript for this? Can I get away with the rails js defaults, or should I be using JQuery?
Is there a way to do this without javascript? I really just need a push in the right direction here, I'm tired of not even knowing how to search for this, or what documentation I should be reading.
Like I said, go easy, and you should just go ahead and err to the side of caution, and assume I know nothing. Seriously. :)
Thanks in advance,
-Kevin
(By the way, I'm developing with Rails 3)
Create your views (along with controllers) to be shown inside the div for each item on the left menu. Lets say we have the following structure now:
Item1 (Clicking on it will fetch:
http://myapp.com/item1)
Item2 (Clicking on it will fetch:
http://myapp.com/item2)
and so on...
make sure you only render the html to be put inside your content div. Should not include <head> <body> etc. tags
In your main page you may have your markup like this >
<div id="leftMenu">
Item 1
Item 2
</div>
<div id="content">
Please click on an item on the left menu to load content here
</div>
Finally, add the following Javascript (you'll need jQuery; trust me it's a good decision).
$("#leftMenu a").click(function () {
$("#content").load($(this).attr("href")); //load html from the url and put it in the #content element
return false; //prevent the default href action
});
You will need JavaScript if you want to avoid reloading the page. You can use link_to for links in your lists, and you'll need to use :remote => true to make it send AJAX requests to the server. The server will need to respond appropriately and supply HTML for your div.
link_to documentation is here: http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to (and admittedly it isn't very useful for AJAX functionality).
The last post in this thread shows one possible solution you could use.

Facebook tags dont render when generated dynamically using Jquery

To give you a simple use case - on my website, I display the comments posted by the facebook users. For each comment I display the facebook users photo using the fb:profile-pic tag and a fb like button.
This page renders properly and everything displays well. Now when the users want to read older comments, they click on the "More" link
Using Jquery, I pull the older comments and in the javascript build the content adding the fb:profile-pic and the fb:like tags
But these tags dont show up. Do we need to reload it or something.
Thanks for your help
First make sure the FBML is being inserted into the DOM with an inspector. If so, all you need to do is tell Facebook to convert the FBML tags to HTML tags so your browser can render it. With the Graph API you call FB.XHTML.parse http://developers.facebook.com/docs/reference/javascript/FB.XFBML.parse using the Javascript SDK. Here's an example from my code:
$('#list').append('<fb:name uid="4"></fb:name>');
FB.XFBML.parse(document.getElementById('list'));
how do I do that - like right now I
build my entire string say
comment="<div>I love
icecream<br/><fb:profile-pic
uid='xxx'></fb:profile-pic></div>"
Then I would do
$("#myswipes").html(comment); So how
would I reload.
you can use $.ajax(), say
$('a.moreComment').click(function(){
$.ajax({
url: 'some/url.php',
success : function(comment){
$("#myswipes").html(comment);
}
});
})
some/url.php should be in the server that can correctly render and return this line, <div>I love icecream<br/><fb:profile-picuid='xxx'></fb:profile-pic></div>

Resources