Jump to content

Deschiderea Automata A Anumitor Linkuri In Pagina Noua (_Bank)


gaby

Recommended Posts

Exista cazuri in care dorim ca toate sau doar unele link-uri de pe o pagina sau un website sa se deschida automat intr-o pagina/fereastra noua, fara a pune pentru fiecare in parte atributul target="_blank". Ei bine, acest lucru este posibil si foarte util in anumite situatii, ca de exemplu in cazul in care avem o pagina cu comentarii, iar aceste comentarii pot contine si adrese web ce dorim sa se deschida intr-o pagina noua.

Pentru asta, creati un fisier external.js care sa contina liniile de mai jos:

var ddwindowlinks={
excludedomains: ["pctroubleshooting.ro"],

linktarget: "_blank",

//Specify operating mode ("auto" or "manual"):
mode: "auto",

//4) If mode is "manual", customize checkbox HTML to show to users (Preserve id attribute):
toggleHTML: '<form><input type="checkbox" id="targetcheckbox" checked="checked" /><label for="targetcheckbox">Open off-site links in new window?</label></form>',

//5) If mode is "manual", enable user persistence so the state of the checkbox is remembered?
persist: true,

assigntarget:function(){
var rexcludedomains=new RegExp(this.excludedomains.join("|"), "i")
var all_links=document.getElementsByTagName("a")
if (this.mode=="auto" || (this.mode=="manual" && this.togglebox.checked)){
for (var i=0; i<=(all_links.length-1); i++){
if (all_links[i].hostname.search(rexcludedomains)==-1 && all_links[i].href.indexOf("http:")!=-1)
all_links[i].target=ddwindowlinks.linktarget
}
}
else{
for (var i=0; i<=(all_links.length-1); i++)
all_links[i].target=""
}
if (this.mode=="manual" && this.persist)
this.setCookie("dlinktarget", (this.togglebox.checked)? "yes" : "no", 30) //remember user setting for 30 days (set to -1 then reload page to erase cookie)
},

init:function(){
if (document.getElementById && this.mode=="manual"){
document.write(this.toggleHTML)
this.togglebox=document.getElementById("targetcheckbox")
this.togglebox.onclick=function(){ddwindowlinks.assigntarget()}
if (this.persist && this.getCookie("dlinktarget")!="")
this.togglebox.checked=(this.getCookie("dlinktarget")=="yes")? true : false
}
if (window.addEventListener)
window.addEventListener("load", function(){ddwindowlinks.assigntarget()}, false)
else if (window.attachEvent)
window.attachEvent("onload", function(){ddwindowlinks.assigntarget()})
},

getCookie:function(Name){
var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
if (document.cookie.match(re)) //if cookie found
return document.cookie.match(re)[0].split("=")[1] //return its value
return ""
},

setCookie:function(name, value, days){
var expireDate = new Date()
//set "expstring" to either an explicit date (past or future)
var expstring=expireDate.setDate(expireDate.getDate()+parseInt(days))
document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+"; path=/"
}

}
ddwindowlinks.init()[/code] si, pe care il chemam prin punerea codului de mai jos intre etichetele [b][color="#FF8C00"]<head> </head>[/color][/b]:
[code]<script type="text/javascript" src="external.js"></script>
A doua linie a fisierului este ocupata de: excludedomains: ["pctroubleshooting.ro"],. In locul adresei pctroubleshooting.ro puneti website-urile pe care doriti sa le excludeti de la regula de a deschide link-urile intr-o pagina/fereastra noua. Exemplu:
excludedomains: ["pctroubleshooting.ro, google.ro"],

Numai bine :pct2: !

Te-ai inregistrat? Ne-ar placea sa te prezinti.

Cum pot sustine forumul?
Cumpara de la eMag folosind acest link.
--------------------
oG2BN9d.gifse1WdXd.gifQG6MtmI.gifRHYjDzD.gifG5p1wui.gif

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.