javascript - Change iframe src through js -


Then coming directly to the problem, I am writing a JS, which src is < Strong> iframe if screen resolution changes

  & lt; Script language = "javascript" & gt; Function newframe () {var w = screen.width; Var srchframe = document.getElementById ("proj"); Var targetURL1 = "http://wms.indianpropertynetwork.com/exchange/frames/clients.featured_projects.asp?cnt=5&wd=880&prj=1"; Var targetURL2 = "http://lpm.indianpropertynetwork.com/exchange/frames/clients.featured_projects.asp?cnt=4&wd=668&prj=1"; If (srchframe.src! = TargetURL1 & amp;> 1300) {srchframe.src = targetURL1} and {srchframe.src = targetURL2}} & lt; / Script & gt;   

And call this function in the following iframe

  & lt; Iframe id = "proj" onload = "newframe ();" MarginWidth = "0" margin-height = "0" width = "100%" height = "200px" frameborder = "0" scrolling = "no" & gt; & Lt; / Iframe & gt;   

The problem with the script is that the URL is loading both URLs and will not stop loading in the alternative URL.

You are using loadloader to start another load cycle, so continuously code again What to do in order to load your code.

Your code:

  1. What is to do on page load in iframe? Call newframe () This is in your code reading onload = "newframe ();"

  2. newframe your if newframe () on any invitation srchframe src . And if URL 1 and url 2 are not, then its URL1 is loading otherwise it is actually the result of swapping both the URLs.

  3. Due to switching to page 2. Second Onload

    The required problem is that srchframe. Specify the URL for src and the page of the frame is changed to load that second page. So do not adjust the src property of the iframe, unless it is actually intended to load any other page in this way.

    In fact, you should try different approaches to take it as described at the beginning:

    iframe src should change if the screen resolution changes

    so you should not force the IFRAME loaded event, but to start the event of an external window. Although it is not working on changing the screen's screen, it is better than your approach. Finally, try the proposed media queries in response to this question:

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -