简体   繁体   中英

display clickable Amazon image links from JAVA to HTML

have a simple calculation that if the selected 2 radio is true it will display the correct link to the div where you can find it. the link is now clickable and opens the right website/URL thanks to User: imvain2 who helped with some of the code. Now when I put an Amazon link in it, it only displays the URL and not the Amazon affiliate clickable Image link.

 <div id="DisplayResults"></div>

    function create_link(url, target_obj){
        var a = document.createElement('a');
        var linkText = document.createTextNode(url);
        a.appendChild(linkText);
        a.title = url;
        a.href = url;
        target_obj.appendChild(a);
    }

function Selectport() {

var aOpticalin = document.getElementById("aOpticalin");
var aOpticalout = document.getElementById("aOpticalout");
var astereoout = document.getElementById("astereoout");
var astereoin = document.getElementById("astereoin");
var DisplayResults = document.getElementById("DisplayResults");


    if(astereoout.checked && aOpticalin.checked){

create_link(<iframe style="width:120px;height:240px;" marginwidth="0" 
marginheight="0" scrolling="no" frameborder="0" src="//ws- 
na.amazon-adsystem.com/widgets/q? 
ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace= 
US&source=ac&ref= 
tf_til& ad_type=product_link&tracking_id=whatsmycable- 
20&marketplace=amazon&region=US&placement=B01HGHNCMW&asins= 
B01HGHNCMW&linkId= 
f3759832fc138a941ade9bde6128b083&show_border= 
true&link_opens_in_new_window= 
false&price_color=333333&title_color=000000&bg_color=d1d1d1">
</iframe>,DisplayResults);
    }
}

That function was originally created based on simply creating a link from a URL. If you would like to append actual precreated HTML, you can use innerHTML.

Make sure to wrap your code in single quotes (apostrophes) if your code has double quotes in it.

DisplayResults.innerHTML += 'Your iframe code goes here';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM