I use a site called finviz.com which provides stock charts. I like to view the charts along different timeframes, one on top of the other. I have been using excel to do this. E.g. if i enter "aapl" in cell A1, I use a simple concatenate formula in excel to put together the hyperlinks I need as follows:
<img src = 'http://elite.finviz.com/chart.ashx?t=aapl&ty=c&ta=st_c,sch_100,sma2_50,sma2_20,sma2_100,stofu_b_5_3_3&p=d&s=l'><br>
<img src = 'http://elite.finviz.com/chart.ashx?t=aapl&ty=c&ta=0&p=i15&s=l'><br>
<img src = 'http://elite.finviz.com/chart.ashx?t=aapl&ty=c&ta=0&p=i3&s=l'>[/code]
however this is pretty slow going. for each different ticker, i need to copy/paste the excel text into an html file on my desktop and refresh my chrome browser. i would prefer to have an input field in my html code that lets me enter a ticker symbol which then dynamically updates the html code for a different stock.
Can anybody suggest how to do that?
One way of doing it is to set up your input box and button, then use jQuery to update the image source.
Add a new input box and button to your HTML and give ids to your images:
<input type="text" id="tickerCode" /><input type="button" id="setTicker" value="Set Ticker" />
<img id="ticker1" src = 'http://elite.finviz.com/chart.ashx?t=aapl&ty=c&ta=st_c,sch_100,sma2_50,sma2_20,sma2_100,stofu_b_5_3_3&p=d&s=l'><br>
<img id="ticker2" src = 'http://elite.finviz.com/chart.ashx?t=aapl&ty=c&ta=0&p=i15&s=l'><br>
<img id="ticker3" src = 'http://elite.finviz.com/chart.ashx?t=aapl&ty=c&ta=0&p=i3&s=l'>
Now on your new button click:
$('#setTicker').click(function () {
$('#ticker1').attr("src", 'http://elite.finviz.com/chart.ashx?t=' + $('#tickerCode').val() + '&ty=c&ta=st_c,sch_100,sma2_50,sma2_20,sma2_100,stofu_b_5_3_3&p=d&s=l');
$('#ticker2').attr("src", 'http://elite.finviz.com/chart.ashx?t=' + $('#tickerCode').val() + '&ty=c&ta=0&p=i15&s=l');
$('#ticker3').attr("src", 'http://elite.finviz.com/chart.ashx?t=' + $('#tickerCode').val() + '&ty=c&ta=0&p=i3&s=l');
});
In case you don't want to use JQuery here is a plain JavaScript version of intracept's very nice code.
<input type="text" id="tickerCode" /><input type="button" id="setTicker" value="Set Ticker" />
<img id="ticker1" src = 'http://elite.finviz.com/chart.ashx?t=aapl&ty=c&ta=st_c,sch_100,sma2_50,sma2_20,sma2_100,stofu_b_5_3_3&p=d&s=l'><br>
<img id="ticker2" src = 'http://elite.finviz.com/chart.ashx?t=aapl&ty=c&ta=0&p=i15&s=l'><br>
<img id="ticker3" src = 'http://elite.finviz.com/chart.ashx?t=aapl&ty=c&ta=0&p=i3&s=l'>
<script>
document.getElementById('setTicker').addEventListener('click', function () {
var symbol = document.getElementById('tickerCode').value;
document.getElementById('ticker1').src = 'http://elite.finviz.com/chart.ashx?t=' + symbol + '&ty=c&ta=st_c,sch_100,sma2_50,sma2_20,sma2_100,stofu_b_5_3_3&p=d&s=l';
document.getElementById('ticker2').src = 'http://elite.finviz.com/chart.ashx?t=' + symbol + '&ty=c&ta=0&p=i15&s=l';
document.getElementById('ticker3').src = 'http://elite.finviz.com/chart.ashx?t=' + symbol + '&ty=c&ta=0&p=i3&s=l';
});
</script>
Related
I'm building a simple webpage.
I wanna select the text inside a <div> and then open a new tab in the same browser and do a Google search for that text with the click of a button. Right now, I just have the solution to copy to clipboard with a button click. Is there any workaround for this...?
I'm OK with using either Google Chrome or Firefox as it's just for a local project. Not meant for public hosting.
UPDATE : I actually need to copy text which is rendered by other HTML code inside the div. I don't wanna copy the code inside the div also.
For reference, here is a code snippet that I used to make my copy to clipboard function.
JavaScript:
function CopyToClipboard(containerid) {
if (document.selection) {
var range = document.body.createTextRange();
range.moveToElementText(document.getElementById(containerid));
range.select().createTextRange();
document.execCommand("copy");
} else if (window.getSelection) {
var range = document.createRange();
range.selectNode(document.getElementById(containerid));
window.getSelection().addRange(range);
document.execCommand("copy");
alert("Copied the text. Use Ctrl+V to paste on Google")
}
}
HTML:
<div class="search" id="div1">
<!--Text to search for (here, CEO of Google)-->
<span>CEO of Google</span>
</div>
<button id="button1" class="button" onclick="CopyToClipboard('div1')">Copy question</button>
This code selects just the text inside the div and then copies it. I don't wanna search for the rest of the code....
Try with the code below.
You can find out more information about how to redirect from your page here.
<html>
<body>
<div id="search_this">New text</div>
<button type="button" onclick="myButtonOnClick()">Search!</button>
</body>
<script>
function myButtonOnClick(){
let url = "https://www.google.com/search?q=";
let searchText = document.getElementById("search_this").innerHTML;
debugger;
window.open(url + searchText);
}
</script>
</html>
This code does the job:
function searchMe() {
var stringQuery = document.getElementById('text_div').innerHTML;
var query = "https://www.google.com/search?q=" + stringQuery.split(' ').join('+');
window.open(query);
}
<div id="text_div" onClick="searchMe();">
Kittens
</div>
Note: Does not work here on stackoverflow but I've tested it in a custom html file and it works.
OK I've got a workaround. Hope it helps someone else with the same problem. A special thanks to both #Daan Seuntjens and #Alex Dragnea for sharing answers as I have used their basic method.
Here, I've selected the text in the <div> and stored it int the range variable which was used earlier for the copy to clipboard function. And then, I did I used another variable query just like both the answers earlier told to add the text https://www.google.com/search?q= to the beginning of the text. And then, I did window.open(query); to open it in another tab and then do a Google search..
NOTE : This code doesn't run here on Stack Overflow. But, I have tested it externally. It is verified and ready to go...
function search(containerid) {
if (window.getSelection) {
var range = document.createRange();
range.selectNode(document.getElementById(containerid));
window.getSelection().addRange(range);
var query = "https://www.google.com/search?q=" + range;
window.open(query);
}
}
<div class="question" id="div1">
<!--Text to search for (here, CEO of Google)....-->
<span>CEO of Google</span>
</div>
<button class="button" onclick="search('div1')">Search</button>
I have a problem with my HTML-Website.
I would like to have a text field which generates a link after entering and pressing a button from the input. For example, in the text field is "development" and by pressing the button should my browser go to "www.laurensk.at/development".
I donĀ“t have the code for that...
I've understood your question, you can do it using JQuery or Javascript
$("#btnGoto").click(function(){
window.location="www.laurensk.at/"+$("#txtPage").val();
});
I hope this will help you.
You can use the addEventListenerfunction to generate the link when there is a new input in the field.
Example:
var path = document.getElementById("path")
var link = document.getElementById("link")
function makeLink() {
link.href = "http://my.web.site/" + path.value
link.innerHTML = "http://my.web.site/" + path.value
}
path.addEventListener("keyup", makeLink)
<input id="path"/>
<br>
<a id="link" target="_blank"></a>
Documentation: EventTarget.addEventListener() - Web APIs | MDN
Currently on button click, I'm able to display the user input from inside the textbox, but it's displayed inside the same Div every time.
Textbox and the button (HTML file)-
<input type="text" name="inputText"><br>
<tr>
<input type="button" value="ADD" ng-click="$ctrl.addtext()">
</tr>
<div id="outputDiv"></div>
JS function-
ctrl.addtext = function () {
var div = document.getElementById('outputDiv');
div.innerHTML += newtext+"\n";
}
How can I get the user input in a different Div and a newline every time?
EDIT: A similar question has been asked for JQuery and it's JS is-
$('#submit').click(function() {
var text = $('#input').val();
$('#newDivs').append('<div>' + text + '</div>');
});
How can I do that append in Angular?
Got it to work using this in the JS function-
div.innerHTML += "<div>"+newtext+"</div>\n";
Instead of-
div.innerHTML += newtext+"\n";
Reference (solved for Jquery)-
Create/Display a new Div each time text is submitted by a user
All I ever wanted is my DropDownList to be special. :(
I can write just names, but that won't be as intresting. So I tried to add images, like so:
// Somewhere in the code...
ListItem item = new ListItem();
item.Value = // something
item.Text = "<img src=\"" + <AnImagePathIGetFromTheDatabase> + "\">";
<MyDropDownlist>.Items.Add(item);
However the evil thing escapes the text in a list automatically, like so:
<img src="https://41.media.tumblr.com/bcb96f4a4c46a1001118ee216d7abacf/tumblr_mgfhbngsDl1r58qimo1_500.png">
So I get text instead of an image. How can I overcome this?
EDIT: Using Lajos' solution, I've got to a situation where I inspect the selection element, And I get the following :
<img src="http://i.somethingawful.com/u/robtg/Fiesta/f05.jpg" alt="monster" height="42" width="42">
Which is pretty much what I was looking for. Sadly, in the page source, I get the following:
<option value="MeaninglessImp" class="imageconverter">http://i.somethingawful.com/u/robtg/Fiesta/f05.jpg</option>
The list itself shows 2 empty cells. The inspector says the pictures have been scaled down to 0x0.
Fiddle: here.
Why does that happen?
You can set the Text to contain the source and not show them until the page is loaded. You can implement a Javascript library which replaces src text with images in your list. That should solve the problem.
// Somewhere in the code...
ListItem item = new ListItem();
item.Value = // something
item.Text = <AnImagePathIGetFromTheDatabase>;
listItem.Attributes.Add("class", "imageconverter");
<MyDropDownlist>.Items.Add(item);
And in Javascript you need something like:
$(function() {
$(".imageconverter").each(function() {
$(this).html('<img src="' + $(this).text() + '">');
});
});
I have images with dynamically generated image maps. I want users to be able to click on the map and be taken through to the <area href= property.
However, when they click on the background (i.e. not in any of the map's areas) I want them to go through to a background URL.
So my code looks something like this (fiddle):
<a href="fromAnchor.html" target="_blank">
<img src="image.png" usemap="#test" />
</a>
<map name="test" id="test">
<area href="fromMap.html">
</map>
In Chrome/FX it works as I expect - if I click in the area tag's shape I get taken to fromMap.html, if I click elsewhere I get directed to fromAnchor.html.
However, in IE (tested up to IE10) clicking on the img but outside the area does nothing. It does show the URL hint in the bottom left corner, but it doesn't follow the a tag.
Is there a way around this?
I came up with a solution, but it's kind of awful (so would be very happy to see a better answer).
My workaround is to dynamically add a fallback <area> that fills the entire image and let clicks outside the exiting area's fall back to it:
var msie = /MSIE/.test(navigator.userAgent);
if (msie)
{
// Don't do this hack twice
$('map[data-iehack!="1"]').each(function ()
{
// First find the image this map applies to
var $this = $(this);
var name = $this.attr('name');
var $img = $('img[usemap="#' + name + '"]');
// Then find if the image is in an <a> tag
var $link = $img.parents('a');
if ($link.length > 0)
{
// If there is an <a> add an extra <area> that fills the image
var wrapLink = $link[0].href;
var width = $img.width();
var height = $img.height();
var $fallbackArea = $('<area shape="rect" coords="0,0,' + width + ',' + height + '" />');
$fallbackArea.attr('href', wrapLink);
$this.append($fallbackArea);
}
// Flag this map so we don't add it again
$this.attr('data-iehack', '1');
});
}
This example is in jQuery but the principal should work in other frameworks.
There has to be a better way than this - and this hack has to check the browser as I can't figure out how to detect IE's failure here.