Create dynamic url from user input - javascript

I am running a blog: http://jokesofindia.blogspot.com. I want to provide a dynamic link in the sidebar of my blog to download a Hindi newspaper in pdf format.
I tried to view source url of epaper.patrika.com and found that if I enter the url epaper.patrika.com/pdf/get/145635/1 it will download the first page and epaper.patrika.com/pdf/get/145635/2 it will download second page, and so on.
The last part of url is the page number. But the second to last part of the url, '145635', changes every day. Now I want to be able to enter this changing part of url manually every day and then have the JavaScript generate download links with the date replaced by the information I entered.
This code also needs to work on mobile devices such as Android.

You can use the html5 data object to store the data and use JS to get that data and append it to the link:
HTML
<div class="linkholder" data-number="12345">
PDF page 1
PDF page 2
</div>
JS
$(document).ready(function() {
var newNum = $('.linkholder').attr('data-number');
$('.linkholder a').each(function() {
var newLink = $(this).attr('href').replace('#', newNum);
$(this).attr('href',newLink);
});
});
view the CodePen to see it in action.

Related

Run Search on Webpage Dynamically

I'm trying to dynamically submit a search form on BBB (Better Business Bureau) then load the results as if you were to go to the web page and enter the search criteria yourself. So far I dont have much, but...
$.post('https://www.bbb.org/search/', {input:"car", location:"New York, NY"}, function(data){ $( "#results" ).empty().append( data ); });
Basically I send the input and location and attempt the load the results in to a div container. I can load the results in to the current page OR just re-route to the page that would load had you manually ran the search. Any ideas on how to do this? I know pages like youtube have search api's for developers but BBB does not (to my knowledge)
You can form the query string for the main search page with "input" and "location". e.g for input : "car" and location : "New York, NY" query strings looks like this
queryString = type=name&input=car&location=New York,NY&tobid=&filter=business&source=bbbse&default-source=bbbad&radius=&country=&language=&codeType="
append this query string to the url. "https://www.bbb.org/search/?" + queryString
which is equivalent to https://www.bbb.org/search/?type=name&input=car&location=New+York%2C+NY&tobid=&filter=combined&source=bbbse&default-source=bbbad&radius=&country=USA&language=en&codeType=YPPA
Now you can set browser window.location (javascript) equal to above url which will route you to desired page with search results.

Use Webpage to Open it in Excel

I'm looking fora functionality that if you press a button or a link inside of a website, it will automatically open excel in you local computer. The button or link that you press is defined with specific data for instance data "test" and you want to have the data inside of the excel after you have pressed the button or link
Please remember that you have the data in the webpage and then when you press on the button or link you open the excel document and the data from the wepage will be transer automatically to the excel document.
Is it possible to do it? if yes, how?
I have tried finding a solution by using sourcecode but I failed.
You can use the ms-excel scheme to open a file in Excel.
A simple example:
<a href="ms-excel:ofe|u|http://berkeleycollege.edu/browser_check/samples/excel.xls">
Open in Excel
</a>
Demo: http://jsfiddle.net/DerekL/mp0p1gcq/
Another demo: http://jsfiddle.net/DerekL/x9npn97z/
Full Syntax Definition for the ms-excel scheme:
Excel Scheme = "ms-excel:" open-for-edit-cmd | open-for-view-cmd | new-from-template-cmd
open-for-edit-cmd = "ofe|u|" document-uri
open-for-view-cmd = "ofv|u|" document-uri
new-from-template-cmd = "nft|u|" template-uri ["|s|" save-location]
document-uri = URI location of document to open
template-uri = URI location of template file upon which new file will be based
save-location* = URI location of folder in which new document should be created
*save-location is an optional parameter

Javascript code to record click on link to PDF - Qualtrics

For a survey experiment built in Qualtrics, I need to record whether respondents clicked on a hyperlink to a pdf document attached to one of my questions. I have set it up so that the pdf document opens in another tab. I am not proficient with Javasctript. What would be the simplest solution to record this information? Thank you in advance!
Another user asked a similar question about tracking hyperlink clicks to an external webpage, but I'm unsure if I can use a click thru when the document isn't exactly an external webpage.
There are 3 pieces to this process:
1: Set your link up with a specific ID for example:
<a id="myLink" href="http://communicus.com" target="_blank">Test Link</a>
2: For the question that you need this on, add the following JavaScript(adjust the ID and embedded data variable in the script as necessary):
Qualtrics.SurveyEngine.addOnload(function()
{
var a = $("myLink"); //adjust ID here
a.onclick = function() {
Qualtrics.SurveyEngine.setEmbeddedData("clicked", 1); //adjust embedded data variable here
}
});
3: Add the embedded data variable, to match your JavaScript, in the survey flow section. Make sure that it exists in survey flow prior to the block your question resides in.
This will let you track those who clicked the link in a Qualtrics variable.

Adding / updating a paramenter in URL with jquery

I have 16 database results shown on my website. Using a load more button, the user can load the next 16 database items and they get appended into the container.
Im trying to make a way so that if the user clicks back after visiting a link, they will get shown the same amount of results as they had loaded.
My plan for this is to add a page number to the url after each load more function. When the user clicks back in the browser, i can then use that parameter in the LIMIT php claus.
So, in my ajax response, i append the data and then i wish to add a page number to the url, or update the page number if there already is one.
An example of what i want to achieve is:
www.mydomain.com/?page=1
I have made a jsfiddle with a basic button click function just for testing since im away from my laptop until later.
jsFiddle
And the code just incase:
var url = document.URL;
var pageID = '1';
$("#addtourl").click(function(){
// add page id to the url
alert(url);
});
Where the url is alerted i want to modify the URL. I already create a page ID so thats not an issue.
Thanks!
You can use the HTML 5 history.pushState function as explained here .

In DashCode, how to access the dataArray from an onClick handler

I have a list that is automatically populated from an XML DataSource using bindings.
Each XML record contains a title, a description and a URL
Each UI row contains a title and a description.
When onclick is called on the title, I would like to call the openURL with the URL specified in the DataSource.
Is it possible to identify the current selection and navigate in the datamodel from the onclickHandler?
In a Dashcode project I'm working on right now I have a datasource that includes a URL to the product on Amazon.com. I haven't done this from the list view, but from my detail view I created a link to the Amazon page for the currently displayed product.
On the detail layout the URL field is transformed to be:
"Click here to purchase the product on Amazon.com."
And the word here is a standard html link.
I used a Value Transformer to do this. In my data source the URL field contains a fully qualified URL to the product on Amazon.com. So where you see "value" in the code below Dashcode is replacing that with a URL in the HTML code that is then included in the page.
myBuildAmazon = Class.create(DC.ValueTransformer,{
transformedValue: function(value){
// Insert Code Here
value="Click <a href="+value+" target='_blank' >here</a> to purchase the product on Amazon.com.";
return value;
}
});
One important thing is that when you bind the datasource to the field select HTML from the popup menu that comes up rather than Text.
I hope this helps.

Categories

Resources