Tags down


pass url variable to javascript

By : Rajveer Singh Chauhan
Date : May 07 2020, 10:07 AM

I have next script that is not giving me the result I want. JSFiddle link at the bottom.

Note: This is not my image. I grabbed it randomly from imgur.

I expect:

<img src="https://i.imgur.com/MiOeWrk.jpg" style="max-width:800px;">

But I get this output , I believe, but I'm unable to write this in a code block while debugging, for some reason.

<img src="http://thisismydomain.com/https://i.imgur.com/MiOeWrk.jpg" style="max-width:800px;">

Here's my script code. Please advise:

<div><a href="javascript:viewimage('https://i.imgur.com/MiOeWrk.jpg','video_aba');">Show Image</a></div>

<div id="jsdebug">jsdebug</div>
<div id="video_aba">video_aba</div>

function viewimage(ytlink, uid) {
  var imagelink = ytlink;
  document.getElementById("jsdebug").innerHTML = imagelink;
  var uid = uid;
  if (imagelink.length == 0) {
    imageembed = "<strong>Sorry, unable to load.</strong>";
  } else {
    imageembed = "<img src=\"/" + imagelink + "\" style=\"max-width:800px\">";
  document.getElementById("video_aba").innerHTML = imageembed;


Answer :

The issue is what your image link coded . It's like this

imageembed = "<img src=\"/" + imagelink + "\" style=\"max-width:800px\">";
 => this will prepend to your current domain url eg.if your domain is localhost it will goes localhost/https://i.imgur.com/MiOeWrk.jpg

So remove / from your image link

Share : facebook icon twitter icon
Related Posts Related Posts :
  • clear array after form submit
  • access data using api
  • div position fixed css
  • add horizontal line between two div
  • disable toggle button css
  • css fixed line height
  • background image not working
  • table cell border
  • text line break css
  • overlay div on div
  • text direction rtl css
  • javascript convert string to an object
  • bind inner div click to outer div
  • jquery ajax oncomplete
  • how to use promise in for loop
  • jquery get element using variable
  • javascript send textbox value
  • pass div class content to another class or id
  • css new line after element
  • css calc not working properly
  • link disabled jquery
  • sql join table to subquery
  • MS Access SQL Issue with OR AND Operators
  • set textarea value using php
  • php merge two arrays into one
  • php form with google captcha
  • update current row in php
  • php date format mysql
  • mysql pdo select query
  • php function return an array
  • PHP mysqldump database to sql file
  • display image query
  • php create array using foreach loop
  • associative array php
  • group_concat in mysql laravel
  • php array_push empty
  • mysql on update cascade not working
  • pdo insert prepared statement
  • mysql insert ignore vs on duplicate key
  • mysql insert into existing row
  • mysql multi insert query
  • mysql group by show all rows
  • php change profile image
  • combine multiple arrays into one array php
  • how to sum values in an array
  • how to get sum of the total time
  • How to Create Facebook live stream without notification using API ?
  • on button click make div visible
  • css affect another element on hover
  • insert line after paragraph word
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org