반응형
Jquery로 페이지 제목 변경
<title>
jquery로 동적 변경 태그 를 만드는 방법은 무엇입니까?
예 : 3 개의 >
기호를 하나씩 추가
> title
>> title
>>> title
$(document).prop('title', 'test');
이것은 단순히 다음을위한 JQuery 래퍼입니다.
document.title = 'test';
>를 주기적으로 추가하려면 다음을 수행 할 수 있습니다.
function changeTitle() {
var title = $(document).prop('title');
if (title.indexOf('>>>') == -1) {
setTimeout(changeTitle, 3000);
$(document).prop('title', '>'+title);
}
}
changeTitle();
제목을 변경하기 위해 jQuery를 사용할 필요가 없습니다. 시험:
document.title = "blarg";
자세한 내용은 이 질문 을 참조하십시오.
버튼 클릭시 동적으로 변경하려면 :
$(selectorForMyButton).click(function(){
document.title = "blarg";
});
루프에서 동적으로 변경하려면 다음을 시도하십시오.
var counter = 0;
var titleTimerId = setInterval(function(){
document.title = document.title + '>';
counter++;
if(counter == 5){
clearInterval(titleTimerId);
}
}, 100);
버튼 클릭시 루프에서 동적으로 변경되도록 두 개를 함께 연결하려면 다음을 수행하십시오.
var counter = 0;
$(selectorForMyButton).click(function(){
titleTimerId = setInterval(function(){
document.title = document.title + '>';
counter++;
if(counter == 5){
clearInterval(titleTimerId);
}
}, 100);
});
사용
$('title').html("new title");
var isOldTitle = true;
var oldTitle = document.title;
var newTitle = "New Title";
var interval = null;
function changeTitle() {
document.title = isOldTitle ? oldTitle : newTitle;
isOldTitle = !isOldTitle;
}
interval = setInterval(changeTitle, 700);
$(window).focus(function () {
clearInterval(interval);
$("title").text(oldTitle);
});
제목 목록을 살펴 보는 일부 코드 (순환 또는 일회성) :
var titles = [
" title",
"> title",
">> title",
">>> title"
];
// option 1:
function titleAniCircular(i) {
// from first to last title and back again, forever
i = (!i) ? 0 : (i*1+1) % titles.length;
$('title').html(titles[i]);
setTimeout(titleAniCircular, 1000, [i]);
};
// option 2:
function titleAniSequence(i) {
// from first to last title and stop
i = (!i) ? 0 : (i*1+1);
$('title').html(titles[i]);
if (i<titles.length-1) setTimeout(titleAniSequence, 1000, [i]);
};
// then call them when you like.
// e.g. to call one on document load, uncomment one of the rows below:
//$(document).load( titleAniCircular() );
//$(document).load( titleAniSequence() );
나는 이것을 사용한다 :
document.title = "your_customize_title";
나는 (그리고 추천한다) :
$(document).attr("title", "Another Title");
IE에서도 작동합니다.
document.title = "Another Title";
Some will debate on wich is better, prop or attr, and since prop call DOM properties and attr Call HTML properties, i think this is actually better...
use this after the DOM Load
$(function(){
$(document).attr("title", "Another Title");
});
hope this helps.
Html code:
Change Title:
<input type="text" id="changeTitle" placeholder="Enter title tag">
<button id="changeTitle1">Click!</button>
Jquery code:
$(document).ready(function(){
$("#changeTitle1").click(function() {
$(document).prop('title',$("#changeTitle").val());
});
});
document.title="your title";
I prefer this.
Its very simple way to change the page title with jquery..
<a href="#" id="changeTitle">Click!</a>
Here the Jquery method:
$(document).ready(function(){
$("#changeTitle").click(function() {
$(document).prop('title','I am New One');
});
});
참고URL : https://stackoverflow.com/questions/7173596/changing-the-page-title-with-jquery
반응형
'program story' 카테고리의 다른 글
로컬 호스트가 아닌 요청을 수신하도록 kestrel 웹 서버를 얻으려면 어떻게해야합니까? (0) | 2020.11.01 |
---|---|
React Native 앱이 JavaScript 코드에서 디버그 또는 릴리스 빌드인지 어떻게 확인할 수 있습니까? (0) | 2020.11.01 |
PHPMyAdmin에 대한 루트 비밀번호 생성 (0) | 2020.10.31 |
특정 요청에 대해 ajaxStart () 및 ajaxStop () 비활성화 (0) | 2020.10.31 |
Laravel 4 : 원시 SQL을 실행하는 방법? (0) | 2020.10.31 |