How to use alt image on iframe tag?

孤者浪人 提交于 2019-12-11 16:46:11

问题


I am using iframe tag as below on my structure and template with webcontent, our business requirement is if video is not available on given link show alter image instead, I thought it should be easy and but after googling on it did not see any better way so thought let me ask here... any idea ?

here is my code looks like

  <iframe  src="${.vars['Embed_Link'].getData()}" width="640" height="360" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>

Btw this is Liferay 6.2 EE


回答1:


there is no alt image in an iframe. An iframe just shows whatever it finds under the URL that you provide to it, indiscriminately.

To mimic something like this: If the website (with the video) that you embed is under your control, you can determine what to show in case no video is available. Currently it might show a 404 error message, a search for related content, an ad, nothing at all.

Another way to mimic is: Find out if the server delivers 404 if a video is not available, then determine (using an Ajax-request) if you'll get 404 or 200 as response code. And only if you get 200, render the iframe, otherwise render your alternative image.

In general, this is quite unrelated to Liferay, and with this hints you might find some code in the regular web development circles



来源:https://stackoverflow.com/questions/47776296/how-to-use-alt-image-on-iframe-tag

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!