How to rotate url in iFrame in javascript


dzmr83

I have 2 arrays (I read from XML file):

  • urlsInclude URL
  • durationsContains an integer representing seconds

I want to iterate through these arrays ( starting from the beginning 0when reaching the end ) to display in an iFrame:

  • urls[0].innerHTMLin durations[0]seconds
  • urls[1].innerHTMLin durations[1]seconds
  • urls[2].innerHTMLin durations[2]seconds

etc...

For this I have the following code:

while (i <= len) {
    $j('.marquee').attr('src',urls[i].innerHTML);
    setTimeout(function(){
        i++;
        if (i >= len) {i = 0;} 
    },parseInt(duration[i].innerHTML) * 1000);
}

Then I realized this would run a million times in a loop before reaching the first timeout calling the function and increasing the timeout i.

So I just want to pause the code, but I immediately see in many stackoverflow questions that doing this is a really bad idea.

So the question is, how can I do this?

As a bonus question...where should I fade in(fade out) and/or fade out(fade out)() between urls?

Denis Segure

Here is a simple solution:

var i = 0;
(function step(){
    $j('.marquee').attr('src',urls[i].innerHTML);
    i = (i+1)%len;
    setTimeout(step, parseInt(duration[i].innerHTML) * 1000);
})();

Note that there is no explicit loop. Only one timeout is set at a time.

If you want to add a fade in and out, you have to load the source in different frames (possibly in the same position) and fade them in and out.

Related


How to Rotate Hue in JavaScript

Lance Pollard I saw a function from to here , which doesn't make sense to me, I thought it would start from 0-360.spin-360360 I want to extend the concept of complementary colors, triples and quads (which are built into another library) and generate arbitrary

How to Rotate Hue in JavaScript

Lance Pollard I saw a function from to here , which doesn't make sense to me, I thought it would start from 0-360.spin-360360 I want to extend the concept of complementary colors, triples and quads (which are built into another library) and generate arbitrary

How to refresh iframe url?

test user I'm using ionic to create an app where iframes are being used to display URLs. Here is the HTML code: <iframe id="myFrame" width="100%" height={{iframeHeight}}> Here is the angular js: $scope.iframeHeight = window.innerHeight;

How to get the url of the iframe?

Lundro How to get an iframe that loads a page in another website (CORS) ?URL iFrameObject.contentWindow.location.href return the goodsCORS Error renew: The user will navigate inside the iframe and get another url which I don't know. This is what I'm checking

How to refresh iframe url?

test user I'm using ionic to create an app where iframes are being used to display URLs. Here is the HTML code: <iframe id="myFrame" width="100%" height={{iframeHeight}}> Here is the angular js: $scope.iframeHeight = window.innerHeight;

How to get the url of the iframe?

Lundro How to get an iframe that loads a page in another website (CORS) ?URL iFrameObject.contentWindow.location.href return the goodsCORS Error renew: The user will navigate inside the iframe and get another url which I don't know. This is what I'm checking

How to refresh iframe url?

test user I'm using ionic to create an app where iframes are being used to display URLs. Here is the HTML code: <iframe id="myFrame" width="100%" height={{iframeHeight}}> Here is the angular js: $scope.iframeHeight = window.innerHeight;

JavaScript rotation - how to rotate counterclockwise?

username I have two shapes to scroll through. I am able to rotate them clockwise, but I want the second shape to rotate counterclockwise. JSFiddle:https://jsfiddle.net/7tLv05on/ Here's the following code I'm using to achieve that: var sdegree = 0; $(window).s

How to rotate triangle animation in JavaScript?

Scott Miller I've spent a long time trying to build a program that takes a triangular polygon element and rotates it clockwise infinitely. The problem I'm facing now is rangeError: Maximum call stack exceeded, and I don't know how to code it in a more practica

JavaScript rotation - how to rotate counterclockwise?

username I have two shapes to scroll through. I am able to rotate them clockwise, but I want the second shape to rotate counterclockwise. JSFiddle:https://jsfiddle.net/7tLv05on/ Here's the following code I'm using to achieve that: var sdegree = 0; $(window).s

How to rotate triangle animation in JavaScript?

Scott Miller I've spent a long time trying to build a program that takes a triangular polygon element and rotates it clockwise infinitely. The problem I'm facing now is rangeError: Maximum call stack exceeded, and I don't know how to code it in a more practica

JavaScript rotation - how to rotate counterclockwise?

username I have two shapes to scroll through. I am able to rotate them clockwise, but I want the second shape to rotate counterclockwise. JSFiddle:https://jsfiddle.net/7tLv05on/ Here's the following code I'm using to achieve that: var sdegree = 0; $(window).s

JavaScript rotation - how to rotate counterclockwise?

username I have two shapes to scroll through. I am able to rotate them clockwise, but I want the second shape to rotate counterclockwise. JSFiddle:https://jsfiddle.net/7tLv05on/ Here's the following code I'm using to achieve that: var sdegree = 0; $(window).s

JavaScript rotation - how to rotate counterclockwise?

username I have two shapes to scroll through. I am able to rotate them clockwise, but I want the second shape to rotate counterclockwise. JSFiddle:https://jsfiddle.net/7tLv05on/ Here's the following code I'm using to achieve that: var sdegree = 0; $(window).s

JavaScript rotation - how to rotate counterclockwise?

username I have two shapes to scroll through. I am able to rotate them clockwise, but I want the second shape to rotate counterclockwise. JSFiddle:https://jsfiddle.net/7tLv05on/ Here's the following code I'm using to achieve that: var sdegree = 0; $(window).s

How to rotate triangle animation in JavaScript?

Scott Miller I've spent a long time trying to build a program that takes a triangular polygon element and rotates it clockwise infinitely. The problem I'm facing now is rangeError: Maximum call stack exceeded, and I don't know how to code it in a more practica

javascript: how to rotate text using javascript?

Dexing I have the following code: <img src="http://www.w3schools.com/html/html5.gif" id="imgid"> <h1 id='header'>Example</h1> <!--This is an example html doc not the real thing!--> <button onclick="spin(document.getElementById('header'));spin(document.getEleme

javascript: how to rotate text using javascript?

ten stars I have the following code: <img src="http://www.w3schools.com/html/html5.gif" id="imgid"> <h1 id='header'>Example</h1> <!--This is an example html doc not the real thing!--> <button onclick="spin(document.getElementById('header'));spin(document.getEl

javascript: how to rotate text using javascript?

Dexing I have the following code: <img src="http://www.w3schools.com/html/html5.gif" id="imgid"> <h1 id='header'>Example</h1> <!--This is an example html doc not the real thing!--> <button onclick="spin(document.getElementById('header'));spin(document.getEleme

javascript: how to rotate text using javascript?

Dexing I have the following code: <img src="http://www.w3schools.com/html/html5.gif" id="imgid"> <h1 id='header'>Example</h1> <!--This is an example html doc not the real thing!--> <button onclick="spin(document.getElementById('header'));spin(document.getEleme

javascript: how to rotate text using javascript?

Dexing I have the following code: <img src="http://www.w3schools.com/html/html5.gif" id="imgid"> <h1 id='header'>Example</h1> <!--This is an example html doc not the real thing!--> <button onclick="spin(document.getElementById('header'));spin(document.getEleme

How to detect current iframe url?

india joleti I wrote a html code to initialize the iframe with another website. My domain name is for example: www.mydomain.com/Index.html at this <iframe src = "www.anotherdomain.com/pages/firstPage.html"/> I want to detect the full new src url whenever the

How to access parameters of URL in iframe?

Javier Munoz I have the following HTML with jQuery code: <div id="info" style="width: 100%; height: 280px; overflow-y: scroll;"></div> var url1 = cbcWMS1.getGetFeatureInfoUrl (evt.coordinate, viewResolution, 'EPSG:3857', {'INFO_FORMAT': 'text/html'}); $('#in

How to detect current iframe url?

india joleti I wrote a html code to initialize the iframe with another website. My domain name is for example: www.mydomain.com/Index.html at this <iframe src = "www.anotherdomain.com/pages/firstPage.html"/> I want to detect the full new src url whenever the

How to access parameters of URL in iframe?

Javier Munoz I have the following HTML with jQuery code: <div id="info" style="width: 100%; height: 280px; overflow-y: scroll;"></div> var url1 = cbcWMS1.getGetFeatureInfoUrl (evt.coordinate, viewResolution, 'EPSG:3857', {'INFO_FORMAT': 'text/html'}); $('#in

How to execute https:// url in iframe

Dexter this is my code <!DOCTYPE html> <html lang="en"> <head> </head> <body> <div id="container"> <iframe src="https://google.com" style="width:1000px;height:1000px"></iframe> </div> </body> </html> and console error, i.e. Refused to display 'https://w

How to detect current iframe url?

india joleti I wrote a html code to initialize the iframe with another website. My domain name is for example: www.mydomain.com/Index.html at this <iframe src = "www.anotherdomain.com/pages/firstPage.html"/> I want to detect the complete new src url whenever

How to detect current iframe url?

india joleti I wrote a html code to initialize the iframe with another website. My domain name is for example: www.mydomain.com/Index.html at this <iframe src = "www.anotherdomain.com/pages/firstPage.html"/> I want to detect the full new src url whenever the

How to execute https:// url in iframe

Dexter this is my code <!DOCTYPE html> <html lang="en"> <head> </head> <body> <div id="container"> <iframe src="https://google.com" style="width:1000px;height:1000px"></iframe> </div> </body> </html> and console error, i.e. Refused to display 'https://w