问题
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