• Resolved Imagecookiejaropen

    (@cookiejaropen)


    Code Embed is wonderful to the point of seeming like magic. And so simple to use. I have one bit of a bug, however. I have a Guess My Number game to go with a blog post. It show up and works exactly as expected on both Mac and Windows, but does not show up—and greatly extends the window—on iOS/iPadOS.

    I have included the code. Is there anything you can see that does not play nicely with iOS/iPadOS, something I should leave out or add? It is vanilla HTML/CSS/JS.

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
    	<meta charset="UTF-8">
    	<meta name="viewport" content="width=device-width, initial-scale=1.0">
    	<meta http-equiv="X-UA-Compatible" content="ie=edge">
    	<title>Number Guessing</title>
    	<style>
    	
    	.lastResult {
    		color: black;
    		padding: 7px;
    	}
    	
    	.guesses {
    		color: #000000;
    		padding: 4px;
    	}
    	
    	button {
    		background-color: #fbfaf6;
    		color: #fbfaf6;
    		width: 144px;
    		height: 36px;
    		border-radius: .25em;
    		font-size: 18px;
    		border-style: none;
    	}
    	
    	#subt {
    		background-color: #00ff0d;
    		color: #000;
    		width: 200px;
    		height: 48px;
    		border-radius: .75em;
    		font-size: 16px;
    		border-style: solid;
    		margin-top: 24px;
    	}
    	
    	#guessField {
    		color: #000;
    		width: 200px;
    		height: 48px;
    		font-size: 24px;
    		border-style: none;
    		margin-top: 24px;
    		border: 5px solid #a1abc8;
    		text-align: center;
    	}
    	
    	#guess {
    		font-size: 18px;
    		margin-top: 20px;
    		color: #263048;
    	}
    	
    	#wrapper {
    		width: 400px;
    		height: 440px;
    		text-align: center;
    		font-size: 24px;
    		color: #000000;
    		background-color: #fbfaf6;
    		box-sizing: border-box;
    		border:0;
    		overflow: hidden;
    		margin: 0 auto;
    		display:block;	
    	}
    	</style>
    </head>
    
    <body>
    	<div id="wrapper">
    		<form class="form">
    			<label2 for="guessField" id="guess">Guess My Number 1 to 100</label>
    				<br>
    				<input type="text" id="guessField" class="guessField">
    				<br>
    				<input type="submit" id="subt" value="Submit Guess" class="guessSubmit"> </form>
    		<div class="resultParas">
    			<br>
    			<p>Numbers Tried: <span class="guesses"></span></p>
    			<p>Tries Remaining: <span class="lastResult">7</span></p>
    			<p class="lowOrHi"></p>
    		</div>
    	</div>
    	<script>
    	// Generate a random number from 1 to 100
    	let randomNumber = parseInt((Math.random() * 100) + 1);
    	const submit = document.querySelector('#subt');
    	const userInput = document.querySelector('#guessField');
    	const guessSlot = document.querySelector('.guesses');
    	const remaining = document.querySelector('.lastResult');
    	const startOver = document.querySelector('.resultParas');
    	const lowOrHi = document.querySelector('.lowOrHi');
    	const p = document.createElement('p');
    	let previousGuesses = [];
    	let numGuesses = 1;
    	let playGame = true;
    	if(playGame) {
    		subt.addEventListener('click', function(e) {
    			e.preventDefault();
    			//Grab guess from user
    			const guess = parseInt(userInput.value);
    			validateGuess(guess);
    		});
    	}
    
    	function validateGuess(guess) {
    		if(isNaN(guess)) {
    			alert('enter a valid number');
    		} else if(guess < 1) {
    			alert('enter a number, 1 or more');
    		} else if(guess > 100) {
    			alert('enter a number, 100 or less')
    		} else {
    			//Keep record of number of attempted guesses
    			previousGuesses.push(guess);
    			//Check to see if game is over
    			if(numGuesses === 8) {
    				displayGuesses(guess);
    				displayMessage(<code>Game Over. My number was ${randomNumber}</code>);
    				endGame();
    			} else {
    				//Display previous guessed numbers
    				displayGuesses(guess);
    				//Check guess and display if wrong
    				checkGuess(guess);
    			}
    		}
    	}
    
    	function checkGuess(guess) {
    		// Display clue if guess is too high or too low
    		if(guess === randomNumber) {
    			displayMessage(<code>CORRECT</code>);
    			endGame();
    		} else if(guess < randomNumber) {
    			displayMessage(<code>Too low. Try again.</code>);
    		} else if(guess > randomNumber) {
    			displayMessage(<code>Too High. Try again.</code>);
    		}
    	}
    
    	function displayGuesses(guess) {
    		userInput.value = '';
    		guessSlot.innerHTML += <code>${guess}</code>;
    		numGuesses++
    		remaining.innerHTML = <code>${8 - numGuesses}</code>;
    	}
    
    	function displayMessage(message) {
    		lowOrHi.innerHTML = <code><h6>${message}</h6></code>
    	}
    
    	function endGame() {
    		// Clear user input
    		userInput.value = '';
    		// Disable user input button
    		userInput.setAttribute('disabled', '');
    		// Display Start new Game Button
    		p.classList.add('button');
    		p.innerHTML = <code><h6 id=&quot;newGame&quot;>Start New Game</h6></code>
    		startOver.appendChild(p);
    		playGame = false;
    		newGame();
    	}
    
    	function newGame() {
    		const newGameButton = document.querySelector('#newGame');
    		newGameButton.addEventListener('click', function() {
    			// Pick a new random number
    			randomNumber = parseInt((Math.random() * 100) + 1);
    			previousGuesses = [];
    			numGuesses = 1;
    			guessSlot.innerHTML = '';
    			lowOrHi.innerHTML = '';
    			remaining.innerHTML = <code>${11 - numGuesses}</code>;
    			userInput.removeAttribute('disabled');
    			startOver.removeChild(p);
    			playGame = true;
    		})
    	}
    	</script>
    </body>
    
    </html>

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author ImageDavid Artiss

    (@dartiss)

    Hi,

    I’m not able to provide support with embedded scripts, as it’s unrelated to what my plugin provides, unless you believe the script is not embedding correctly on iOS (i.e. the above script is not appearing in the displayed page as-is).

    Thanks.

    Thread Starter Imagecookiejaropen

    (@cookiejaropen)

    Yes, that is what I am saying. The script does not appear. It does not appear on iOS/iPadOS and now does not appear on Mac or Windows. I tried a second very simple script and it does not appear on any device either.

    Plugin Author ImageDavid Artiss

    (@dartiss)

    I’ve had a look and it doesn’t work on Safari on MacOS either. But does on Firefox.

    I can’t see the code at all in Safari and although it appears in Firefox, some of it is missing – e.g. the opening line of <!DOCTYPE html>. Embedding a new DOCTYPE and HEAD within an existing one is likely to cause issue anyway.

    My plugin doesn’t differ its output depending on browser – it would either work or wouldn’t. I do see that you have caching in place on the site, so not sure if that’s related.

    Here’s how my plugin works – when displaying page content, my plugin hooks into this and replaces your tag (e.g. {{code1}}) with your script. The fact that the hook isn’t showing in Safari, shows this has fired. I would strongly suggest that something else, maybe another plugin, is possibly modifying the output further or restricting it.

    Thread Starter Imagecookiejaropen

    (@cookiejaropen)

    Following up on your suggestions.

    (1) I deleted the DOCTYPE and HEAD and am just using BODY and SCRIPT.

    (2) I found a confict with Meks Flexible Shortcodes and deactivated it. That plug-in had a conflict with another earlier (UpdraftPlus).

    With (1) and (2), I can now see both the simple and more complex scripts exactly as intended on my Mac and Windows desktops. However, they still do not show on iPhone or iPad.

    David, you mentioned caching. I am using WP Super Cache to speed up the site. Is caching a possible conflict with Code Embed? I deactivated it, but the problem remains on mobile.

    Plugin Author ImageDavid Artiss

    (@dartiss)

    Yes, that’s done something and I can now see the code in Safari, albeit it’s still not working.

    I don’t think the caching is at fault.

    So the script is being added to your page now and that means my plugin is doing what it should do. Why is it not working in Safari? That’s down to the script itself and that’s what I can’t offer help with.

    Thread Starter Imagecookiejaropen

    (@cookiejaropen)

    It works now. The conflict is with the Meks Flexible Shortcodes plugin. I am using a Meks theme. I will let them know about the conflict of plugins.

    Thanks for your help and patience. Much appreciated.

    Plugin Author ImageDavid Artiss

    (@dartiss)

    I’m glad to know you got it fixed – great sleuthing! 😊

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Fine on Mac/Win but not on iOS’ is closed to new replies.