Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Resolving URNs with JavaScript
Old 08-13-2007, 03:21 PM Resolving URNs with JavaScript
Moldarin's Avatar
Extreme Talker

Latest Blog Post:
Keyword Density and Title Tags
Posts: 201
Trades: 0
Hi,

Code:
<a href="urn:isbn:<isbn>">Book</a>
I want to apply onclick="resolveURI()" to all urn:isbn: links on-load. This function should set window.location="http://www.amazon.com/dp/<ISBN>".

DOM scripting, of course.
__________________
I do not share ad revenue.
Moldarin is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-13-2007, 04:16 PM Re: Resolving URNs with JavaScript
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Are you looking for a hint on how to do it; or for a ready made js code ?

By the way, an onclick won't do in your case. At least not with firefox.
You will need to replace the href, otherwise, you will have the browser telling you that uri: is not a registered protocol.
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 08-13-2007 at 04:17 PM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 08-13-2007, 04:28 PM Re: Resolving URNs with JavaScript
Moldarin's Avatar
Extreme Talker

Latest Blog Post:
Keyword Density and Title Tags
Posts: 201
Trades: 0
I am looking for a way to find all urn:isbn: hrefs. There is where my problem lies.

The Firefox issue can be resolved by simply removing the HREF value all together.
__________________
I do not share ad revenue.
Moldarin is offline
Reply With Quote
View Public Profile
 
Old 08-13-2007, 04:40 PM Re: Resolving URNs with JavaScript
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Ok, I just wanted to check if you where looking for a free freelancer.
Sorry, me just being paranoid.


For that, the most DOM compliant way is to add an event that will scan every tags "a" in the page, and rewrite their href. No need to drop them.
HTML Code:
<html>
  <head>
    <title>dfg</title>
  </head>
  <body>
    <script type="text/javascript">
      function handleUri(){
        var ary=document.getElementsByTagName('a');
        var aryTmp = new Array();
        var isbn=null;
        var i=0;
        for(i=0;i<ary.length;i++){
          if(ary[i].href.indexOf(':isbn:')!=-1){
            //This is an isbn url
            aryTmp=ary[i].href.split(":");
            isbn = aryTmp[2];
            ary[i].setAttribute('href','http://www.amazon.com/dp/'+isbn);
          }
        }
      }

      try{
        window.addEventListener('load',handleUri,true);
      }
      catch(r){
        window.attachEvent('onload',handleUri);
      }
    </script>
    <a href="urn:isbn:<isbn1>">Book</a><br/>
    <a href="urn:isbn:<isbn2>">Book</a><br/>
    <a href="urn:isbn:<isbn3>">Book</a><br/>
    <a href="urn:isbn:<isbn4>">Book</a><br/>
    <a href="http://www.google.com">Not isbn!</a><br/>
  </body>
</html>
Note that here, I consider that the href to handle are always containing ":isbn:", it ignores every other links
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 08-13-2007 at 04:41 PM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 08-19-2007, 02:48 PM Re: Resolving URNs with JavaScript
Moldarin's Avatar
Extreme Talker

Latest Blog Post:
Keyword Density and Title Tags
Posts: 201
Trades: 0
Why did I not get an email notification about your reply? :S That was odd.

Anyhow: Thanks for your code. I will try and make it work a little faster (it was slow, no offence) and post my improvements here.
__________________
I do not share ad revenue.

Last edited by Moldarin; 08-19-2007 at 02:53 PM..
Moldarin is offline
Reply With Quote
View Public Profile
 
Old 08-19-2007, 03:44 PM Re: Resolving URNs with JavaScript
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
It's not that slow, but it depends of the number of links you have.
What you can have seen as slowness is that this script wait for the page to be completely loaded to be run.
So, yes, it can wait a couple of seconds before being run, but if you want to catch every links on the page, there are not that much choices, afaik...
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 08-19-2007, 10:09 PM Re: Resolving URNs with JavaScript
Moldarin's Avatar
Extreme Talker

Latest Blog Post:
Keyword Density and Title Tags
Posts: 201
Trades: 0
I stumbled upon upon a possible security whole in Firefox 2 while trying to smarten up your code. (I will of course not discuss the whole. Submitted it to Mozilla.) However I was not able to make the code work any faster. BUT when I restarted my computer and ran your code again; it magically worked instantaneous! I have no idea why.

I will rely on your code for URN resolution until Internet 2 is available for everyone!

Thanks for the help tripy.
__________________
I do not share ad revenue.

Last edited by Moldarin; 08-19-2007 at 10:12 PM..
Moldarin is offline
Reply With Quote
View Public Profile
 
Old 08-23-2007, 05:11 AM Re: Resolving URNs with JavaScript
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
BUT when I restarted my computer and ran your code again; it magically worked instantaneous! I have no idea why
It's because (being client side code) it runs as fast as the browser will let it. If your browser has already used a lot of resources then it will be slow, as it tries to use even more resources when reading the page in memory.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Resolving URNs with JavaScript
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.45067 seconds with 12 queries