I am using this cool script http://qpoit.com/marcofolio_demo/apple_search/ however when I click on a search result, I want it to be added as html content to an id which I will use like . I know this is done with $("#displayContent").html(data); however I need the content of search result that I clicked on to be and not all the results found. Please help
The rpc.php-file of the search, contains the function, which generates the output of the search.
In line 29, change the content to a JavaScript-function, which does this work for you.
// Used in line 29 in rpc.php
echo '<a href="'.$result->url.'">';
// Change it to something like
echo '<a onclick="applyContent('.$result->url.')">'
After that, head back to the index.html (or the file in which you are using the apple-search), make sure jQuery is loaded and add something like this:
<script type="text/javascript">
// Use the same function name, as in the php-file
function applyContent (resultURL) {
// Use jQuerys get-function to get the content of the file you've found in the search
$.get(resultURL, function(data) {
// Change '#finalResult' to the css-selector, of the element, which should contain the result at the end
$('#finalResult').html(data);
});
}
</script>
Once you click on a search-result, it should make it the content of #finalResult, or whatever element you choose.
Related
I worked on a little startpage for my browser. Now I would like to make some changes to it, so it updates the index.html file depending on a text file, when this got changed. What whould be an efficiant way to solve this problem?
My approach would be to create a text file and read line by line from it and update the html file. In the text file I would store the links shown on my startpage - I thought maybe something like this:
|cat_media
https://mailbox.org,mail
https://netflix.com,netflix
...
http://crunchyroll.com,crunchy
https://jott-uh-be.bandcamp.com,bc
|cat_social
https://pr0gramm.com,pr0
https://stackoverflow.com,stackoverflow
https://twitter.com,twitter
https://instagram.com,insta
When the line starts with the symbol |, it creates a new <div> with the class category and the string in that line (e.G. class= 'category cat_media'). Otherwise, if the line starts with http, it will add a href-link (e.G. <a href='https://mailbox.org'>mail</a>) to the html-code.
I got this website hosted on my raspberry pi with nginx and uploaded it to my github pages.
You don't have to update the index.html file.
You can create dynamic content.
You can use PHP:
You can learn it here:
https://www.w3schools.com/php/default.asp
And here is how to read a file
http://php.net/manual/en/function.fread.php
Or if you cant use PHP you can use Javascript:
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script>
$(() => {
$.ajax({
url:'your-config-file.xt',
success: function (data){
console.log(data); //this is the config file. just for loop it and modify the dom
}
});
});
</script>
But your config file must contains the string how the links should be shown.
For example:
|catergory one
yt: https://www.youtube.com
We'd like to show a "Loading..." image when the page is still being transferred. Pages can get quite large in our application. I tried with a separate page that displays the image and then loads the intended page, but the animated GIF just stops.
Can something be done on the page itself?
Or is there a better way?
Thanks for your comments, as always!
UPDATE
Here's the general idea of my small switching page:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xc="http://www.ibm.com/xsp/custom">
<xp:div
style="width:84.0px;height:84.0px;position:fixed;top:50%;left:50%;margin-top:0px;margin-left:0px;height:0px;width:0px;z-index:1000"
id="AjaxLoader">
<xp:image url="/loading.gif" id="image1">
</xp:image>
</xp:div>
<xp:scriptBlock id="scriptBlock1">
<xp:this.value><![CDATA[XSP.addOnLoad(function() {
var href= getParameterByName("href");
location.href= href;
});]]></xp:this.value>
</xp:scriptBlock>
</xp:view>
Loading a "loading" page prior than the one you want to load is not an option.
You can create to DIVs in your HTML: one for the loading icon (e.g. with id="loadingIcon"), second one for the content (id="contentWrapper"). The second one is hidden (CSS style="display:none").
Define a Javascript function like this:
function pageLoaded(){
document.getElementById("loadingIcon").style.display = "none";
document.getElementById("contentWrapper").style.display = "";
}
The script is called in the BODY's onLoad event like this:
<body onload="pageLoaded()">
...
</body>
It is not a question of the web-server environment, but how you organize your code :-)
Take your approach and modify it slightly. Instead of location.href = href - which just triggers a reload, use an ajax call and replace your loading div. Something like this:
<xp:scriptBlock id="scriptBlock1">
<xp:this.value><![CDATA[XSP.addOnLoad(function() {
var href= getParameterByName("href");
$.ajax({
url: "test.html",
context: $("#{id:AjaxLoader}");
}).done(function(result) {
$( this ).replace(result);
});
location.href= href;
});]]></xp:this.value>
</xp:scriptBlock>
(contains typos, adjust as needed)
To answer my own question: No, it's not possible, but there is a nice way around this, in my case anyway.
The trick is to open a new browser window, write something in it and then allow the new page to load.
var w= window.open();
w.document.write("<div style='position: fixed; top: 48%; left:40%'>Loading...</div>");
w.location.href= url;
If necessary the text can be replaced by an image and the new url can be set after a timeout.
I know that it is possible to send a user to a specific a name by using a link; however, for what I'm doing, I'd prefer not to use this link element.
Ex:
http://www.domain.com/link.php#aname
will send the user down to
<a name="aname">
Is there a method of doing this on page load, like perhaps adding a line of code to the body tag or something?
I'm using this in conjunction with PHP, so basically if a particular variable is defined, I will be sending them to the location. I know how to do the PHP side of it, just not the html side of it without the use of the link element.
Use the animate method from jquery to get a nice smoothe effect
$("#down").click(function () {
$('html,body').animate({
scrollTop: $("#b").offset().top
});
});
Example
Update: onload
$(document).ready(function () {
$('html,body').animate({
scrollTop: $("#b").offset().top
});
});
Cheers!!
Few Assumptions :
You know/declared the ID/NAME
You are sure that a NAME/ID exist
Recommendation :
Use Id along with the name.
Make sure you have unique Id for that part of page where you want to send the user to.
Add this simple javascript before the end of </body> tag OR after all ids are echo
<script type="text/javascript">window.location.hash=id;</script>
Please change id to your required id. Once the page load first the div with a declared id is created and when everything is complete the javascript will try to move the page to the specific part.
If you will use scrollto then it requires far more steps and is complicated. You will need to
measure the page height
measure the location of that id
scroll to that id if possible
Hope it works for you
currently I am using a button whose 'value' i am able to change so that text written over button changes but I see that text is centered inside button & not big enough . Can I get something like +,- we see in windows explorer which enables to fold & expand folder in tree view.
i do not want to use any external file (img etc.) as I am creating a single self-sufficient webpage.
Please suggest.
you can use this code for displaying + sign
----Firstly put this code in the head of your html.
<script type="text/javascript">
function function_Name()
{
alert('hi');
}
</script>
Then call the above function from this link here below, onclick event here call the above declared function:
+
I use a frame from a HTML page to load some data from the server without having to leave the original web page. I simply reassign the src of the frame and the shown data gets updated.
Now I need to programatically create a div, but the width and height have to be retrieved from the server. May I use a frame to get those values, without leaving the web page, or is there a more simple and efficiente way ?
I would prefer not to use ajax, and keep my code as simple as possible, thanks
One easiest way is to call page property like this:
<script type="text/javascript">
var width = <%=this.Width %>
</script>
and declare this property in cs file like this
public int Width
{
get;
set;
}
Is it what you expected? or if you have some calculations after pages loaded, you can simply achieve it by using jquery ajax and one httphanlder.
Use jQuery. It's really simple.
A simple example:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script>
$('#result').load('otherfile.php');
</script>
<div id="result"> </div>
Loads otherfile.php inside the div id'ed "result". No page reload.
Thanks for the jquery example, I may use it in the future. For now I found a very simple and efficient way to solve it using a frame (I know, I know...) that really surprised me for its simplicity:
I create a form (a javascript class that manages several divs), then a little frame inside it, and the frame change the form properties and remove itself.
The key was to access the javascript variable defined in the parent from the child:
echo "<script>";
echo "parent.window.oDlg.SetSize( ".$row[ "WIDTH" ].", ".$row[ "HEIGHT" ]." );";
echo "parent.window.oDlg.SetTitle( '".trim( $row[ "TITLE" ] )."' );";
echo "</script>";