Update favicon via link in text box and button [closed] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
Sorta like
when you click the button, you get the favicon.ico from the link (using js)
an example ico would be stackoverflow favicon
//this is the js section
//some way to read the text box and Retrieve favicon from link
<button Id=button Onclick=<!--add Update favicon function here -->
Favicon.ico</button>
<input type=box id=field text="input Text here">

If I understand what you're asking correctly, this should work:
function updateFavicon(link){
let exists = $("link[rel*='icon']");
if(exists.length){
$("link[rel*='icon']").attr('href', link);
} else {
$("head").append("<link rel='icon' href='" + link + "'>");
}
}
And then:
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<div>
<input type="text" id="link">
<button onclick="updateFavicon($('#link').val())">Update Favicon</button>
</div>

Related

How do I switch html pages with JavaScript if I don't have the Url [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 17 hours ago.
This post was edited and submitted for review 17 hours ago.
Improve this question
I have them both as HTML files in my repo. The button is just meant to switch from pages for now. I will add the function for the inputs and conditions later. I just want to get in working before I add anything. There are also no errors that or popping up. I cannot use a tag as I need to change the URL to pass data through it, so I need to have it in JS so I can change it with the data from the input.
The plan is to have the user put in their name in a text input, and have it inside the Url, then have the 2nd page process the name and output a text and photo.
This is the code that I have tried.
const nameButton = document.getElementById("nameBtn");
$(nameButton).click(function(){
preventDefault()
function change_page(){
window.location.replace("page-two.html");
};
change_page()
});
This is the Html:
<input class="font" type="text" id="inputName" value="Type in
your name..."></input>
<button class="fonts" id="nameBtn">Ready?</button>
</form>
</div>
</body>
<script src="scripts/script.js"></script>
</html>
Short answer, only replace the pathname
window.location.pathname = 'page-two.html'
In your case:
const nameButton = document.getElementById("nameBtn");
nameButton.addEventListener('click', function (event) {
event.preventDefault()
window.location.pathname = "page-two.html";
});

how to get the full html element using jquery? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I want to get all full element using class
<div class="number">one</div>
<div class="address">addr1</div>
<div class="number">twod</div>
I want what are all the div having class name number, I want output full content with tags one by one using foreach statement. The expected output is like below
<div class="number">one</div>
<div class="number">two</div>
$('.number, .address').each(function() {
console.log(this.outerHTML)
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="number">one</div>
<div class="address">addr1</div>
<div class="number">twod</div>

javascript/html: Remove element by ID on button click [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
In short, what I want to do is make it so when I click a button in my HTML document, I want that button to subsequentely be removed by it's ID, using javascript if possible. I've been searching for a solution with no success, can anyone help me out here?
In your HTML:
<button onclick="deleteSelf(this)">Click me</button>
In your JavaScript:
function deleteSelf(button) {
button.remove();
}
This works:
https://jsfiddle.net/00p4oLfy/
document.getElementById('test').remove();
<p id="test">This is a test</p>
<p id="test2">This is another test</p>
Html
<div>
<button id="ClickMe">Click Me</button>
</div>
Javascript
document.getElementById('ClickMe').remove();

Onclick image the gallery opens [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am working on a mobile application, I am trying to make an image as a button: I have an image and I want to click on it, then when I click the mobile gallery opens so that I can upload a photo.
Any help please?
I think, you want to open file-uploader on image button click! Right?
If so, you can use pure javascript / jQuery as following:
HTML:
<div id="profilepic">
<input id="fileSelector" type="file" name="file" accept="image/*" capture="camera" />
<button id="clickButton" onClick="openFileUpload();"><img src="Images/profilepic.png" width="170" height="170"/></button>
</div>
For jQuery append this to head of your document:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
Wrap following code in head too.
JQuery:
$(document).ready(function(){
$('#clickButton').on('click', function(){
$('#fileSelector').click();
});
});
OR Javascript:
function openFileUpload(){
document.getElementById('fileSelector').click();
}
http://jsfiddle.net/mas5qr1o/1/
See demo here:
jQuery DEMO
Javascript DEMO
Try the following jquery
$('#clickButton').on('click', function(){
$('#fileSelector').trigger('click');
});
DEMO

How on one click another page div value change using JavaScript? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have two page page1.php, page2.php and one JS file Control.js.
In page1.php
HTML :
<img src="images/b.jpg" width="31" height="26" id="imgClick1" onClick="return changeImage1(this)" >
In Control.js
function changeImage1() {
document.getElementById("imgClick1").src = "images/b.jpg";
document.getElementById('num1').style.color = "#fff";
document.getElementById("text1").innerHTML = "Hello friend";
}
In page2.php
<div id="text1">
Hello world
</div>
So using JavaScript I am trying to write "hello friend" in the div "text1" of page page2.php when I click the image or the div of page1.php.
Is there any possible way to use JS to solve this problem?
Can we use any how document.getElementById("text1").innerHTML or something like that in the program?
I suggest you make use of the include function of php (provided you absolutely want to keep your text1 div on a separate page), like this on your page1.php file:
include('page2.php');
Make sure that when you do that, page1.php and page2.php are in the same folder, otherwise you may define a path to it like this:
include('/path/to/page2.php');

Categories