Welcome to WebmasterWorld Guest from 3.227.233.6

Forum Moderators: open

Message Too Old, No Replies

Javascript code as <href> value - is it possible

     
11:01 pm on Jul 20, 2015 (gmt 0)

New User

joined:July 20, 2015
posts: 37
votes: 0


Hello

I have a such code

 <a href="tel:1111"></a>


Site owner asked my to include Javascript code as a link. Something like this

 <a href="tel:<script type="text/JavaScript" src="https://***/js/keyword_replacement.js"></script>"></a>


it's a 2 block javascript code (1st block i must include in head and the second block will generate phone number - each time new nubmer).

So my question is - is it possible to include such a code into href="tel:"

Like this


<a href="tel:<script type=\"text/JavaScript\" src=\"https://**/js/keyword_replacement.js\"></script>">1</a>

or

<a href='tel:<script type="text/JavaScript" src="https://**/js/keyword_replacement.js"></script>'>1</a>
or
<a href="tel:<script type="text/JavaScript" src="https://**/js/keyword_replacement.js"></script>">1</a>


No of this code didn't work properly

Any advice will be appreciated.

-
David
3:12 am on July 21, 2015 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 15, 2003
posts:958
votes: 33


You can't embed one HTML tag within another. You need to create the original text in JavaScript as well as call the external script. Your code needs to be something like:

<script type="text/javascript">
document.write('<a href="tel:');
</script>
<script type="text/JavaScript" src="https://***/js/keyword_replacement.js"></script>
<script type="text/javascript">
document.write('">1</a>');
</script>
4:54 am on July 21, 2015 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:15754
votes: 827


document.write ? Really? (Sure, I've used it, but in most circumstances I'd be scared to death of obliterating the whole page by mistake.)
6:21 am on July 21, 2015 (gmt 0)

Senior Member

WebmasterWorld Senior Member topr8 is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Apr 19, 2002
posts:3491
votes: 80


or you could give the a href tag an id, you could then run a script that writes the telephone number (on page load)

... the main question is why do you want to do this?
if the client thinks the telphone number won't be scraped by writing it in js, they may be mistaken, especually as once the phone number is out there, other sites will use it in their directories and those directories get scraped anyway.
11:22 pm on July 21, 2015 (gmt 0)

New User

joined:July 20, 2015
posts: 37
votes: 0


thank you guys

Topr8
No, the problem is other. My client is using dialogtech_com phone pool, that's why we put this js code on webpage. Each time page loads, it generates new phone number (so phone numbers are dinamic). That's the reason why i can not use static numbers.
6:32 am on July 22, 2015 (gmt 0)

Senior Member

WebmasterWorld Senior Member topr8 is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Apr 19, 2002
posts:3491
votes: 80


ah! fair enough.