Replace Page Links on Popup Page With Javascript
I have a popup player for my radio station website. The window has links
to various other pages in my site, some of which are created dynamically
by Wordpress widgets.
I want the links to open in the parent window as most of the content isn't
suitable for the small popup window.
The approach I have taken is to use javascript to re-write the links as
target="parent". This works (from the footer) with the following script.
<script>
var aEls = document.getElementsByTagName('a');
for (var i = 0, aEl; aEl = aEls[i]; i++) {
aEl.href = aEl.href.replace('target="_self"','target="_parent"');
}
var imgEls = document.getElementsByTagName('img');
for (var i = 0, imgEl; imgEl = imgEls[i]; i++) {
imgEl.src = imgEl.src.replace('target="_self"','target="_parent"');
}
</script>
However, this only works for static links on the page, and not those
generated via my slider widget or another widget.
Is there some place this needs to be included, or an adjustment able to be
made to find and replace all links after that have been generated?
No comments:
Post a Comment