Reply to topic
Snap Preview Anywhere javascript snippet
Allen
Forum Regular

Joined: 06 Apr 2004
Posts: 410
Location: Willcox, AZ
Reply with quote
This question is in reference to the fairly new (and super cool) search engine called Snap at http://www.snap.com/ which offers a free feature called "Snap Preview Anywhere" which will show the viewer a quick snapshot of the webpage associated with a hyperlink. In other words, before a viewer clicks a link, they can see the webpage it goes to. It is somewhat similar to the 'binoculars' of Ask. com and seemingly would be a nifty feature for my directories. (pardon my use of 'nifty'... jargon of the early 1950s)

Anyway, since I don't want this 'preview' to be displayed for my internal links (being then a stupid feature), Snap suggested this:

Q: How do I turn off Snap Preview Anywhere for internal links?*

A: You need to add the 'snap_nopreview' tag to each of those links. This can done manually or via JavaScript such as the example below:

<script type="text/javascript">
//<![CDATA[
//change sites internal links to class "snap_nopreview"
var links = document.getElementsByTagName('a');
for (var l = 0; l < links.length; l++) {
if(links[l].href.match(/^http:\/\/www\.example\.com/)){
links[l].className += " snap_nopreview";
}
}
//]]>
</script>


Well, this snippet doesn't work (I don't like the manual option) and I think it has to do with this part: (/^http:\/\/www\.example\.com/) Of course, for my site I tried: (/^http:\/\/www\.matrixbookstore\.biz/)

Is it because my internal links don't spell out the whole URL? For example: <a href="idiot.htm">idiot</a>

I tried several variations but since I'm not smart enough to be a hack, nothing works... any suggestions?
Allen
Forum Regular

Joined: 06 Apr 2004
Posts: 410
Location: Willcox, AZ
Reply with quote
Problem solved... for Explorer 7 at least. By revising this portion thusly, it worked:

if(links[l].href.match(/matrixbookstore\.biz/)){

On the other hand, Firefox wouldn't ignore the internal links if they're enclosed in brackets or situated within the borders. For all other links it did work.

I tried inserting the caret (^) character thusly: (/^matrixbookstore\.biz/), but then not even Explorer 7 would recognize it. Maybe I need an 'excape'... another backslash (\) or something?

UPDATE: While it worked perfectly for Explorer 7 at first, but now, for some reason, it isn't working for those links on the right side and bottom borders. It only works for those links within the body and left border.

P.S. As instructed, I placed the code just before the (/body) tag. I also tried placing in before the (/head) tag but then the script wouldn't work at all.

I'm hornswoggled!
body.onload = nopreview();
comprug
Forum Regular

Joined: 15 Feb 2006
Posts: 343
Reply with quote
Allen, don't quote me on this, but this is what I would do. In the opening body tag:
Code:
<body onload="noSnapshot();">

Now before the end of the body tag:

Code:
<script type="text/javascript">
//<![CDATA[
//change sites internal links to class "snap_nopreview"
function noSnapshot() {
var links = document.getElementsByTagName('a');
for (var l = 0; l < links.length; l++) {
if(links[l].href.indexOf('matrixbookstore.biz') != -1){
links[l].className += " snap_nopreview";
}
}
}
//]]>
</script>
Allen, also consider this: what if the link was /contact.htm instead of matrixbookstore.biz/contact.htm. While they accomplish the same thing, what if javascript processes them differently in IE and FF?
Thanks,
[/i]
Allen
Forum Regular

Joined: 06 Apr 2004
Posts: 410
Location: Willcox, AZ
Reply with quote
Thank you Ben!! It works perfectly for Explorer 7... see http://www.matrixbookstore.biz/azcolleges.htm (changed just this one webpage)

However, it doesn't work at all for Firefox. Like you said though, FF might be processing the script differently.

And, as you suspected, none of my internal links have the 'http://www.matrixbookstore.biz/' portion. In other words: <a href="example.htm">example</a> whereas my external links would be: <a href="http://www.example.edu/">example</a>

While I'm happy with this, any ideas for FF without compromising IE?
Some minor changes
comprug
Forum Regular

Joined: 15 Feb 2006
Posts: 343
Reply with quote
Allen, try this:
Code:
<script type="text/javascript">
//<![CDATA[
var ua = navigator.userAgent.toLowerCase();
//change sites internal links to class "snap_nopreview"
function noSnapshot() {
var links = document.getElementsByTagName('a');
for (var l = 0; l < links.length; l++) {
if(links[l].href.indexOf('matrixbookstore.biz') != -1){
if (ua.indexOf("firefox") != -1) {
links[l].setAttribute("className", " snap_nopreview");
} else {
links[l].className += " snap_nopreview";
}
}
}
}
//]]>
</script>
Allen
Forum Regular

Joined: 06 Apr 2004
Posts: 410
Location: Willcox, AZ
Reply with quote
No difference Ben... it works for IE but not for Firefox.

I left the <body onload="noSnapshot();"> in place and refreshed the page (whereby it wasn't a cache).

Nonetheless Ben, I'm still happy with the existing fix... just thought you might have a quick idea off the top of your head. You've already put too much time in this for which I thank you.
Snap Preview Anywhere javascript snippet
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic