Alternative to WebGL if not loading - php

I have some WebGL stuff in an iframe. On some web browsers or old computers, the iframe isn't loading. When this happens I'd like to load an image instead. Is it possible and if yes how to do it ?
Thanks

Wether or not WebGL is supported is probably best checked the same way you do in Javascript
WebGLRenderingContext gl = canvas.getContext("experimental-webgl")
if(!gl)
{
$("#image").show()
}

Problems in <script>:
First of all it seems that you have some problems within your <script> tag. There is plain <center><iframe ... HTML tags inside <script> tag which does not work as there should be only javascript here. There is also some missing ; semicolons.
Solutions to detect WebGL:
You could try this one but I also recommend checking out linked sites at end of my answer:
?>
<script type="text/javascript">
if (!window.WebGLRenderingContext) {
var myImage = new Image();
myImage.src = "http://domain.tld/picture.jpg";
$(myImage).prependTo(document.body);
} else {
$(document.body).prepend('<center><iframe ALLOWTRANSPARENCY="true" frameborder="0" height="340" width="454" src="CORRECT THIS FIELD"></iframe></center>');
}
</script>
<?php
Just add echos for PHP and correct <iframe src="CORRECT THIS FIELD"> attribute, also set image url to something that really exists.
In place of document.body you could use for example '#myWebGLArea' and add <div id="myWebGLArea"></div> to your page.
More on topic:
Also check out WebGL detection script at https://gist.github.com/1709384 and another Q/A https://stackoverflow.com/a/9904965/1338846

Related

how to convert every youtube link i have on my wordpress posts into embed?

i am using the latest version of wordpress , i have around 10000 post right now on my website.
i have a nice plugin that makes my website looks a bit more fancey but i need to ad a simple code to each featured image and each embeded youtube video i have in my posts (if i could pick user who add it too that would be perfect ! ) to get it to work
i know that youtube embed code is
<iframe width="560" height="315" src="//www.youtube.com/embed/NrH9CqnzzRU?list=PLHPcpp4e3JVpXbtgyD-k-nCmwpbbMIHOh" frameborder="0" allowfullscreen></iframe>
what i need to do is to add
<div class="featuredvideo"><iframe width="560" height="315" src="//xxxxxxxxxxxxxxxxxxxxxxxxx" frameborder="0" allowfullscreen></iframe></div>
so i want to add those things before and and after "XXXX" s
i am not a programer so please give me the code
i know that AJAX can search entire folder with code like
<button>AJAX</button>
<br>
<div id = "container"></div>
<script type="text/javascript">
$("button").click(function(){
$.get("sample.html",function(data){
$("#container").html(data);
})
});
which will just get html from a file but that is now what i want to do here.
please help me , give me a plugin or a code to work with
thank you
To wrap the Youtube iframes with the div as required, just use this...
$(function() {
$("iframe[src*=www.youtube.com]").wrap("<div class=\"featuredvideo\" />");
});
That will run when the document has finished loading. It will find all iframes with the string www.youtube.com in the src attribute and wrap them in the required div.
Obviously, if you add any more iframes to the page later and it doesn't reload then you'll need to run that code again. If you did just that then it would wrap the iframes in the div again, which would be wrong. This will handle running the code multiple times...
function wrapYoutubeEmbeds() {
$("iframe[src*=www.youtube.com]").each(function() {
if (!$(this).parent().hasClass("featuredvideo")) {
$(this).wrap("<div class=\"featuredvideo\" />");
}
});
}
$(function() {
wrapYoutubeEmbeds();
});
It simply checks to see if each iframe is inside something with the class featuredvideo and ignores it if it is.

point browser to image and use jquery?

How can I manipulate image in browser with jquery when the image is retrieved with:
http://slideshopro.com/dunlap-hall-entry-tower/wp-content/uploads/sites/621/2014/06/DSC02599.jpg?imageOnly=true
I tried to put:
if($_GET['imageOnly'] == true) {
?>
<script type=text/javascript>
jQuery(document).ready(function($) {
console.log('image');
}
</script>
<?php
}
in index.php and in functions, but I could not get it to run.
Hard to tell exactly what you are asking here, but if you are talking about manually manipulating the image, that will be tough to do with jQuery alone, especially if you want to do something with the manipulated image. You will need to work HTML5 Canvas.
I suggest you check out fabric.js, they created a powerful and simple Javascript HTML5 canvas library.

Google Chrome: URL could not be located

I have a large website with many hard coded pages. If there is a broken URL Firefox doesnt seem to care. But Google Chrome and IE seem to display a horrible placeholder box (as if there should be an image in its place).
What is the best solution to scan the page of broken images? and assigning display:none to the image to stop the placeholder showing up?
function imgError(image){
image.onerror = "";
image.src = "/images/noimage.gif";
return true;
}
<img src="someimage.png" onerror="imgError(this);"/>
I found the above client side solution. But is there a way with PHP do it before the page is loaded? I am using concrete5
For cases like this use the 'alt' HTML tag. This tag is used to display a description of the img in case it is not found.
<img src="myPath.png" alt="Here was my broken image">
If images are on same server then try file_exists function to check if there's image. If not show something else.
Here's the code to help you:
if(file_exists("../img/logo.png")) {
echo '<img src="../img/logo.png" />';
} else {
//something else
}

Display cross domain page inside div, iframe, frame with original height?

I have created a page in which I am showing A websites Page (situated some where on web );
I used iframe but puzzled with the height issues I solved width issues for 950px only with css3 but my need is full height as target website but that is not working with cross domain pages (I've done with same domain successfully).
Now I want to do it either with PHP using get_file_content() or some other putting it into div , iframe or in frames whatever works (and also pages must be accessible as it is from main sites)
The container will change its content with hyper link click.
Please help me to resolve the issues.
I've tried many more methods including jquery, js, php, css and blah blah blah with no success.
before commenting or answering please visit THIS LINK
I need some thing like this
Please check this and alter here
To See My page Click here
Note:
I have no access of target site so I can't put attributes on target
page and get back to iframe page.
I have 100+ pages to show so no
specific method can be used i need any generalized technology.
One more thing i don't want scrolling in my page.
Efforts done :
Ajax/Jquery
PHP Resize
In the "iframe'd" html, have:
<body onload="parent.resize_iframe(document.body.scrollHeight)">
and in the page that iframes:
<script type="text/javascript">
function resize_iframe(new_height) {
document.getElementById('iframed').style.height = parseInt(new_height, 10) + 60 + 'px';
}
</script>
I used 60px to fix potential padding etc.
Note that they have to be under the same domain for this to work, otherwise you might have to run:
<script type="text/javascript">
document.domain = "domain.com";
</script>
On either or both. This is required so that the browser may interact between them.
Do something like this:
<frameset rows="*">
<frame frameborder=0 src="http://www.discountautoparts.com/" scrolling="auto" noresize>
</frameset>
If you do that it should look like this picture

"Body Onload" to send "ScrollHeight" not working properly in Chrome and Safari

I just asked a question here, about why an iframe_resize function wasn't working.
After troubleshooting, I found out that the problem is not the function, so I am posting a new question.
I have an index.html with this resize function:
function resize_iframe(new_height){
document.getElementById('iframe001').style.height=parseInt(new_height) + 20 + 'px';
}
Then I have a form in index.html with target set to an iframe, and action set to query.php:
<form action='query.php' target='iframe001'>
The in my query.php:
//ALOT OF PHP HERE
<body onload="parent.resize_iframe(document.body.scrollHeight)">
<?php echo $results_table; ?>
</body>
The problem is, in Chrome and Safari, the scrollHeight isn't changed at all.
In all other browsers, scrollHeight changes and the function works.
However, in Chrome/Safari, when clicking on a link anywhere on the page, and then clicking on the browser back button to return to the search results (iframe content), THEN the iframe is resized properly even in Chrome/Safari... ?
This is very strange behaviour for me.
Can somebody explain this?
Thanks
PS: I think this person has the same problem: iframe resizing with scrollheight in chrome/safari
Did you try offsetHeight property?
It seems there is a bug in general with webkit browsers. https://bugs.chromium.org/p/chromium/issues/detail?id=34224&can=2&start=0&num=100&q=&colspec=ID%20Pri%20M%20Stars%20ReleaseBlock%20Component%20Status%20Owner%20Summary%20OS%20Modified&groupby=&sort=
WORKAROUND(!): I had margin applied to a wrapping element like this inside the iframe:
<div class="wrapper" style="margin-top: 30px"><!-- ... content --></div>
changed it to be instead:
<div class="wrapper" style="padding-top: 30px"><!-- ... content --></div>
then scrollHeight is correct :)

Categories