I am building webpage with several pages.i don't want to use links to go to those pages. i have given the page numbers in the bottom of the page. but when i click that page number the page should information of other page should in the same page.how can i achieve this?
If you don't want to redirect to another page you have to use a frame (the easier way, but really uglier) or AJAX. The AJAX code is easy, if you need it I'll post by comment :)
Chris Coyier at CSS-tricks has a great article explaining a non-frame SEO friendly technique for doing just that.
var oXHR = new XMLHttpRequest();
oXHR.open("get", "page.php?num=1", true); // here you get the page you need
oXHR.onreadystatechange = function ()
{
if (oXHR.status != 200)
document.getElementById('page_displayed').innerHTML = "Error: " + oXHR.status + " " + oXHR.statusText;
else
document.getElementById('page_displayed').innerHTML = oXHR.responseText;
// here will be displayed your content
}
oXHR.send(null);
This is the AJAX code. Then in "page.php" you would have to write something like (I'll write in pseudo-code):
<?php
// ipotize you see 10 post for every page
$post = 10;
$page_num = $_GET['num'];
// select from database the content you need
$sql = "SELECT content FROM pages LIMIT 0, ".$post;
// OR (if you have more html contents for different pages)
// if ($page_num == 1)
{
?>
<html code here>
<?php
}
// in each case you must return some text, it will be displayed on your page
?>
Ask if you don't understand :)
Yes frames is going to be the best thing for you.
Is the link for details http://www.w3schools.com/html/html_frames.asp
Related
As the title says, is it possible to embed the latest post of my blogger to the main index.html of the website?
The website main page is https://my-domain.com/index.html and the blog https://blog.my-domain.com. I want to embed the latest blog post to specific place on my website's main page. i.e. main page automatically updates when I post on my blogger.
Is this possible?
You can use jsonp of your blog, create div like this for place of latest post <div id="latest-post"></div>
<script src='http://your-blog.com/feeds/posts/default?alt=json-in-script&callback=latestPost' async='async'></script>
<script>
function latestPost(json) {
var entry = json.feed.entry;
for(var i = 0; i < entry.length; i++) {
var link, title = entry[i].title.$t;
for(var j = 0; j < entry[i].link.length; j++) {
if(entry[i].link[j].rel === "alternate") {
link = entry[i].link[j].href;
}
document.getElementById("latest-post").innerHTML += "<a href='" + link + "'>" + title + "</a>";
}
}
}
</script>
You could use iframes - this would simply embed the page contents in another page. For example:
<iframe src="http://google.com" width="800" height="800" title="Embed google.com"></iframe>
However, iframes present big security risks (for example, cross-site scripting) - avoidable but a better approach would be something like Fajar recommends (i.e grab the content from the Blogger API, decode the JSON and set your content to the values downloaded).
In future, when you ask questions on Stack Overflow, include the code that you've already tried to get you to the solution. If you don't know how to do something, research the subject and use jsfiddle or similar to prototype things.
I am trying to scrape data from a news article using HtmlAgilityPackage the link is as follows http://www.ndtv.com/india-news/vyapam-scam-documents-show-chief-minister-shivraj-chouhan-delayed-probe-780528
I have written the following code below to extract all the comments in this articles but for some reason my variable aTags is returning null value
Code:
var getHtmlWeb = new HtmlWeb();
var document = getHtmlWeb.Load(txtinputurl.Text);
var aTags = document.DocumentNode.SelectNodes("//div[#class='com_user_text']");
int counter = 1;
if (aTags != null)
{
foreach (var aTag in aTags)
{
lbloutput.Text += lbloutput.Text + ". " + aTag.InnerHtml + "\t" + "<br />";
counter++;
}
}
I have also used this XPath but still the same result //div[#class='newcomment_list']/ul/li/div[#class='headerwrap']/div[#class='com_user_text']
Please help me with the correct Xpath to Extract all the comments
Searched all over the net but no solution.
Do a 'View Source' on the page and search for com_user_text. The user comments don't appear at all. They are loaded via javascript after the page is loaded. So when you load the page content via getHtmlWeb.Load(), you don't get user comments.
As this answer says, HTML Agility is not a tool capable of emulating a browser and running javascript. Instead, you need something like WatiN that "allows programmatic access to web pages through a given browser engine and will load the full document."
...I know how to establish short URLs (using .htaccess) that remove the "index.php" from URLs. Now my Wiki main page URL looks like www.site.com/wiki/Main_page. However, i want it to simply look like www.site.com/wiki/ . Is it possible to do this without heavy modifications to the source code?
Yes, this can be done now. The main trick is to tell MediaWiki what the canonical URL of your main page is. To have the main page in the domain root:
$wgHooks['GetLocalURL'][] = function ( &$title, &$url, $query ) {
if ( $title->isExternal() || $query != '' && $title->isMainPage() ) {
$url = '/';
}
};
See http://laxstrom.name/blag/2015/08/31/mediawiki-short-urls-with-nginx-and-main-page-without-redirect/ for full details.
I'm using getJSON to get data from the facebook pages api, and it works just fine, using this code:
$(document).ready(function(){
$.getJSON('url',function(json){
$.each(json.data,function(i,fb){
var output='';
//here I add to output, as this example line:
output += '<div"><a href="http://www.facebook.com/profile.php?id='+fb.from.id+'>'+fb.from.name+'</a>';
$("#results").append(output);
});
});
However, what I'd like to do is similar to what facebook does in it's social plug in where it starts off with 5 entries and has a Show More link, which when clicked, brings in 5 more entries.
Is there a way to do this by altering the code I have?
Thanks
Well, sure there is. Do you want to fetch the other results when a user clicks the "more link" to save bandwidth or is it OK to fetch it at the same time? (async vs sync)
This answer considers the bold text:
output += '<div' + (i >= 5 ? ' style="display: none;"' : '') + '><a href="http://www.facebook.com/profile.php?id=' + fb.from.id +'>'+fb.from.name+'</a></div>';
Oh, and check that line in your code, you had a syntax error and an unmatched div. Also you should have quotation marks around your HTML element's attributes.
For showing the links when the more link is clicked you could do something like:
$('.more').click(function() {
$(this).hide();
// Find the closest ancestor which is a parent of both
// the more link and the actual results list
var $parent = $(this).closest('.parentSelector');
$('.listSelector', $parent).children().show();
return false; // Don't follow the link
});
The parts with the parent stuff above is for the case when you have multiple such results list on the same page and you need to separate them. If you don't need it, here is a simpler variant:
$('.more').click(function() {
$(this).hide();
$('#results').children().show(); // Show all other list items
return false; // Don't follow the link
});
Here is the situation: I have 2 pages.
What I want is to have a number of text links(<a href="">) on page 1 all directing to page 2, but I want each link to send a different value.
On page 2 I want to show that value like this:
Hello you clicked {value}
Another point to take into account is that I can't use any php in this situation, just html.
Can you use any scripting? Something like Javascript. If you can, then pass the values along in the query string (just add a "?ValueName=Value") to the end of your links. Then on the target page retrieve the query string value. The following site shows how to parse it out: Parsing the Query String.
Here's the Javascript code you would need:
var qs = new Querystring();
var v1 = qs.get("ValueName")
From there you should be able to work with the passed value.
Javascript can get it. Say, you're trying to get the querystring value from this url: http://foo.com/default.html?foo=bar
var tabvalue = getQueryVariable("foo");
function getQueryVariable(variable)
{
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++)
{
var pair = vars[i].split("=");
if (pair[0] == variable)
{
return pair[1];
}
}
}
** Not 100% certain if my JS code here is correct, as I didn't test it.
You might be able to accomplish this using HTML Anchors.
http://www.w3schools.com/HTML/html_links.asp
Append your data to the HREF tag of your links ad use javascript on second page to parse the URL and display wathever you want
http://java-programming.suite101.com/article.cfm/how_to_get_url_parts_in_javascript
It's not clean, but it should work.
Use document.location.search and split()
http://www.example.com/example.html?argument=value
var queryString = document.location.search();
var parts = queryString.split('=');
document.write(parts[0]); // The argument name
document.write(parts[1]); // The value
Hope it helps
Well this is pretty basic with javascript, but if you want more of this and more advanced stuff you should really look into php for instance. Using php it's easy to get variables from one page to another, here's an example:
the url:
localhost/index.php?myvar=Hello World
You can then access myvar in index.php using this bit of code:
$myvar =$_GET['myvar'];
Ok thanks for all your replies, i'll take a look if i can find a way to use the scripts.
It's really annoying since i have to work around a CMS, because in the CMS, all pages are created with a Wysiwyg editor which tend to filter out unrecognized tags/scripts.
Edit: Ok it seems that the damn wysiwyg editor only recognizes html tags... (as expected)
Using php
<?
$passthis = "See you on the other side";
echo '<form action="whereyouwantittogo.php" target="_blank" method="post">'.
'<input type="text" name="passthis1" value="'.
$passthis .' " /> '.
'<button type="Submit" value="Submit" >Submit</button>'.
'</form>';
?>
The script for the page you would like to pass the info to:
<?
$thispassed = $_POST['passthis1'];
echo '<textarea>'. $thispassed .'</textarea>';
echo $thispassed;
?>
Use this two codes on seperate pages with the latter at whereyouwantittogo.php and you should be in business.