I have a website. I want a search box to appear under the main page of my website in google. I have my own custom search engine and search bar in the website. I did a bit of research and found out that you need a chunk of code like this:
<script type=”application/ld+json”>
{
“#context”: “http://schema.org”,
“#type”: “WebSite”,
“url”: “https://www.panpact.com/”,
“potentialAction”: {
“#type”: “SearchAction”,
“target”: “https://query.panpact.com/searchresults.php?search={search_term_string}&page=1&con=1”,
“query-input”: “required name=search_term_string”
}
}
</script>
I have changed the above code to replace example with my website name(Panpact).
I am not sure if it works though. When someone on my site searches and presses enter they are redirected to the search page and the url looks like:
http://panpact.com/searchresults.php?search=Hello&page=1&con=1
First of all is my above Script code correct for what I want to do? And why is their the word query in front of the domain in the target field? Do I need it?
Related
I have a school project where I want to be able to take an input from another forum site I have made, and then show this on my main HTML site.
I have a way to get the information from my forums site to my main with this cod on my HTML main site:
const input = window.location.search;
localStorage.setItem("fname", input);
document.getElementById("demo").innerHTML =
localStorage.getItem("fname");
ps getElementById "demo" is the id name for the output.
The problem here is that the visual output is: ?FNAME="input from my forum site" instead it should only show the input from my forum site.
I have tried to use text.replaced but it ended up not showing anything at all.
So, I'm writing a Chrome extension for a school assignment and I'm stuck on this part where I think I need to parse a string. This is my first time working with HTML, CSS, and JS, so I'm just scouring the web for tips on how to make this happen.
Basically, in our assignment we need to create an extension for Chrome which essentially opens up a new page where we have a search bar. There's this website, https://www.manualslib.com/, and the terms we input into that search bar need to be used to directly search that site.
The problem is that this website's URL for searches is a bit different than what I'm used to: when you search for something, the website takes the first letter of my search term, puts it in between slashes, and then adds at the end the whole search. For example, if you search genetics there, the URL will look like https://www.manualslib.com/g/genetics.html.
So I guess I need to parse the string somehow to get the search term's first character, right? According to w3schools, using the split() method would be a good idea. The problem is I'm not really sure how the syntax works here. As I said, it's my first time dabbing in web developing, so I'm not familiar at all with the way people do stuff here. Any help is appreciated.
This is the code I have for the search bar (this code merely redirects to the webpage, it doesn't search anything):
<div id="tfheader">
<form id="tfnewsearch" method="get" action="https://www.manualslib.com/">
<input type="text" class="tftextinput" name="str" ; size="21" maxlength="120">
<input type="submit" value="search" class="tfbutton">
</form>
</div>
What kind of changes do I have to make? Do I need to create a .js file where I write the function that parses the string? Or is the parsing function written inside the HTML file? Any help is appreciated, thanks in advance!
var query = 'genetics';
var url = 'https://www.manualslib.com/{0}/{1}.html'
.replace('{0}', query.substring(0, 1))
.replace('{1}', query);
console.log(url);
The onsubmit event might help you.
To redirect to another site, just set window.location, like this:
search_form.onsubmit = function() // will be called as soon as the form is submitted
{
var searchText = typehead.value; // the text entered in the search bar
var redirectTo = "https://www.manualslib.com/"+searchText[0]+"/"+searchText+".html";
window.location = redirectTo;
}
I have the following javascript
$(document).ready(function() {
$('a[href*="profile"]:contains("David")')
.closest('td').find('.fightMobster').click();
});
This searches the page content for the word 'David' and clicks the link.
I'm wanting to progress this. Instead of searching the page contents, I want to search for the LINK text.
For example, the link to 'David' might be http://www.example.com/164522
So I'd like to search the page for 164522 instead.
Also, I'd like to implement a form where you can specify the text you are searching for. Sort of a text box where you can type 164522 and a button which starts and stops to search process.
In your case you should use
$('a:contains(David)')
I really need to know how I can autofill text boxes on a web page.
What I really want to achieve is the following:
1) Go to http://show.websudoku.com
2) Replace all the empty cells with a 0 (zero).
Is that possible?
To fill the empty spaces of the Sudoku grid at http://show.websudoku.com with zero's, here is some JavaScript to do that. It is formatted for use as a "Bookmarklet":
javascript:(function(){var x,k,f,j,r;x=document.forms;for(k=0;k<x.length;++k){f=x[k];for(j=0;j<f.length;++j){r=(f[j].className.toLowerCase()+f[j].type.toLowerCase()+f[j].value);if(r=="d0text"){f[j].value="0";}else if(r=="d0text0"){f[j].value="";}}}})();
The setup:
Create a new Bookmark/Favorite. For now, the URL for the favorite can be anything. An easy way to do this is to drag ANY link/url from the browser address bar, or any web-page link, to the "Favorites Bar" or to the Bookmarks/Favorites sidebar.
Select the new favorite, and rename it to any name you like.
Copy the JavaScript code from above to the clipboard. It must remain as 1 continuous single line, and it must begin with "javascript:(" and end with ")();"
Edit the properties of the new favorite.
Remove the "URL" that is currently in the favorite and replace it by pasting in the JavaScript code from above, into the "URL" text field for the favorite, then save the changes.
To use the bookmarklet:
From the browser, navigate to http://show.websudoku.com as you normally would.
Click the new favorite (Bookmarklet) that you just edited.
All empty spaces in the Sudoku grid will be filled with 0's. Click the new favorite (Bookmarklet) again, and the 0's will be removed leaving empty spaces once again.
Here is what the Javascript code looks like expanded, with indents:
javascript:(function(){
var x,k,f,j,r;
x=document.forms;
for(k=0;k<x.length;++k){
f=x[k];
for(j=0;j<f.length;++j){
r=(f[j].className.toLowerCase()+f[j].type.toLowerCase()+f[j].value);
if(r=="d0text"){
f[j].value="0";
}
else if(r=="d0text0"){
f[j].value="";
}
}
}
}
)();
* Spoiler alert *
In case you want to "cheat", the JavaScript here will "solve" the Sudoku:
javascript:(function(){var x,k,f,j,ecl,etl,en,ev,s,e,c,d,dl,dr,n;x=document.forms;for(k=0;k<x.length;++k){f=x[k];for(j=0;j<f.length;++j){e=f[j];r=(e.name.toLowerCase());if(r=="cheat"){c=e.value;break;}}for(j=0;j<f.length;++j){e=f[j];ecl=e.className.toLowerCase();etl=e.type.toLowerCase();en=e.name;ev=e.value;if(etl=="text"){if(ecl=="d0"){dr=en.substr(en.length-1,1);dl=en.substr(en.length-2,1);d=(((Number(dr)-1)*9)+Number(dl))-1;n=c.substr(d,1);if(ev.length==0){e.value=n;}else{e.value="";}}}}}})();
Setup and use is the same as described above.
While it's not much fun to solve it like that (OK, maybe it's a little fun the first couple times), and definitely not challenging, if you are in a real-real-real hurry, you can solve it in 1 click.
Note: I have only tested these 2 bookmarklets with IE9.
I have a form which is using a select list to jump around my site. This is currently using onclick window.location so user selects the page and presses go and it goes to that page.
I now need to add a small text box for the user to type in a code (say 123456) and then when they click go, it should go to the url selected, but with the [CODE] being the number entered in the box. I discovered jquery replaceAll so it gave me the idea to have this in the select html:
http ://jumptothispage.com/parts/p[CODE]/edit
http ://jumptothispage.com/jobs/j[CODE]/edit
When you press go, it would replace all [CODE] in that html with the code entered and then jump to that page selected, e.g.
http ://jumptothispage.com/parts/p123456/edit
http ://jumptothispage.com/jobs/j123456/edit
I am already using jquery on my site so makes sense to try and utilize that again. I'd appreciate a pointer and or other suggestions instead.
Thanks,
Paul.
A workaround: Store the code in a cookie, so at least it's not visible to every person who looks at the URL bar. Then in every onclick, fit it into the URL to send the user to the "right" page.
Or, have your select option's value literally read CODE, which your onclick interprets to mean "The user hasn't set the code yet." When the user types in the code, store it in a variable (in the example below, realcode), and you can then do this:
$('select#navigation option').each(function(idx, el) {
$(el).attr('value', $(el).attr('value').replace(/CODE/, realcode));
});