Replace html attribute with Javascript

Hey,

I am trying to modify an href attribute using javascript. Specifically, I want to replace “about:blank” with “tel:+19055764442”. Here is the code I am attempting to implement unsuccessfully. I have placed this before the body tag.

<script>
var a = document.querySelector('a[href="about:blank"]');
if (a) {
  a.setAttribute('href', 'tel:+19055764442')
}
</script>

I am using this method because I used Snazzy Maps to create a custom map, and the Snazzy Maps editor replaces “tel:+19055764442” with “about:blank”. So I am unable to add a telephone link to the custom map.

Any help is appreciated.


Here is my site Read-Only: LINK
(how to share your site Read-Only link)

You need to access the element inside your iframe first.

1 Like

Hey Gail_Ranger,

Thanks for your response. Your answer would be correct if my iframe source was not external. I was unable to find a way to target the iframe content; I think this is due to the “Same Origin” policy.

So your issue is still unresolved?
What happens if you target the iframe like this?
let iframe = document.querySelector('iframe');

You are correct. If the IFRAME is not the same origin you can’t manipulate its contents.

1 Like