0
How do I creat a JavaScript code to replace a name for a JavaScript code?
Like this one but instead of replacing a url, it should replace a name for a JavaScript code. <script type="text/javascript"> var elements = document.getElementsByTagName("a"); for(var i=0;i<elements.length;i++){ elements[i].href = elements[i].href.replace("google.com","google.net"); } </script>
8 Réponses
+ 5
Maybe something along these lines?
https://code.sololearn.com/WoVWth9Mp702/?ref=app
+ 5
To retrieve the div, query document.foo(), where foo() is:
.getElementById("?"); // single result
.getElementsByClassName("?"); // array
.getElementsByTagName("div"); // array
If you get an array, loop to find the right element:
for(var el in retrievedArray)
// scan retrievedArray[el].innerHTML for keyword
To find keyword...
http://www.dyn-web.com/javascript/strings/search.php
Then replace:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace
0
but how is the script going to be like?
0
but this way it won't replace anything, I want to replace a text for a JavaScript code.
0
because I want to add this script only on pages where there is this specific name.
0
Thanks for trying to help but using this way it will only replace a script for another script, I need a script to find a name inside a div tag and then replace this name for a script which is this Script <script type="text/javascript">
var adlinkfly_url = 'https://shrtner.ga/';
var adlinkfly_api_token = '1cb03faa96023ceab3d9628251998b2effa53094';
var adlinkfly_advert = 2;
var adlinkfly_domains = ['depositfiles.com', 'uploading.com', 'uploadable.ch'];
</script>
<script src='//shrtner.ga/js/full-page-script.js'></script>
- 1
If you want to replace the link text, which the user can see. Try element[i].innerHTML.
- 1
Maybe this works:
elements[i].innerHTML = "Text I want to be now here."
Instead of:
elements[i].href = elements[i].href.replace("google.com", "google.net");
I hope this is what need.