pyroman131
12-27-2005, 06:11 PM
I'm trying to create a script where all the hyperlinks in a page will be replaced with a new set of coding before it. (e.g: a href="this.htm?http://www.google.com").
My code generates this change through a series of random numbers and only runs the script when "2" is the generated number (out of 12). Now, I only know how to replace all occurrences of "href" in all "a" tags, but there are times when I use Javascript to launch new windows or even javascript to navigate to the top of a page.
I tried to use a string match method to search for occurrences of "javascript:" and so forth, but I can't seem to get it working.
Here's what I got so far:
function loadInterstitial() {
var ranNum = Math.round(Math.random()*11);
var adUrl = "ad.htm";
if (ranNum == 2) {
var links = document.getElementsByTagName("a");
for (var i=0; i<links.length; i++) {
var redir = links[i].href;
var JScript = links.match("javascript:");
if (JScript = true) {
links[i].href = redir;
} else {
links[i].href = adUrl + "?redir=" + redir + "&timer=3000";
}
} else if (ranNum != 2) {
return ranNum;
}
}
I'm trying to get a page to load in between browsing (such as an interstitial, only not as annoying). I can make it appear for every link fine and randomize it as I please, but I can't seem to get this part to work.
Problem: I don't want the script to load the new url when I'm using javascript to launch new windows in "a" tags. (e.g: a href="javascript:scroll(0,0)" is changed to a href="ad.htm?javascript:scroll(0,0)"). Is there any way around this?
I tried using external Javascript files to write out the code "a href='javascript:scroll(0,0)", but this script still detects it and writes the code before this link. I don't want to use IFRAMEs, because they are hard to manipulate with my site.
Solution, please?
My code generates this change through a series of random numbers and only runs the script when "2" is the generated number (out of 12). Now, I only know how to replace all occurrences of "href" in all "a" tags, but there are times when I use Javascript to launch new windows or even javascript to navigate to the top of a page.
I tried to use a string match method to search for occurrences of "javascript:" and so forth, but I can't seem to get it working.
Here's what I got so far:
function loadInterstitial() {
var ranNum = Math.round(Math.random()*11);
var adUrl = "ad.htm";
if (ranNum == 2) {
var links = document.getElementsByTagName("a");
for (var i=0; i<links.length; i++) {
var redir = links[i].href;
var JScript = links.match("javascript:");
if (JScript = true) {
links[i].href = redir;
} else {
links[i].href = adUrl + "?redir=" + redir + "&timer=3000";
}
} else if (ranNum != 2) {
return ranNum;
}
}
I'm trying to get a page to load in between browsing (such as an interstitial, only not as annoying). I can make it appear for every link fine and randomize it as I please, but I can't seem to get this part to work.
Problem: I don't want the script to load the new url when I'm using javascript to launch new windows in "a" tags. (e.g: a href="javascript:scroll(0,0)" is changed to a href="ad.htm?javascript:scroll(0,0)"). Is there any way around this?
I tried using external Javascript files to write out the code "a href='javascript:scroll(0,0)", but this script still detects it and writes the code before this link. I don't want to use IFRAMEs, because they are hard to manipulate with my site.
Solution, please?