using navigator.platform to change iframe src

Discussion in 'JavaScript' started by chrisdavies, Nov 27, 2009.

  1. #1
    hi,

    I need to be able to change the src of an iframe based on what computer a user has (mac/PC).

    I have got the script to do the detection part but not sure how to get it to change the src in the iframe.

    any help much appriecated

    chris
     
    chrisdavies, Nov 27, 2009 IP
  2. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #2
    well, if you can detect the OS and have which url should iframe be loaded with on detection of a particular OS, then simply add following line in javascript where you want to load the iframe..

    window.frames[FRAME_NAME].src = SRC_URL;

    where
    FRAME_NAME = name of the frame you wish to load with url.
    SRC_URL = the url you wish to load into frame.

    Hope this helps, if confused, post your detection code and urls for different OS. We will help you write a js code for the same.
     
    mastermunj, Nov 30, 2009 IP
  3. Amit Oxy

    Amit Oxy Guest

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    if using jquery then user is like

    if(mac){
    $('#iframeid').attr('src','source1')
    }else{
    $('#iframeid').attr('src','source2')
    }
     
    Amit Oxy, Nov 30, 2009 IP
  4. chrisdavies

    chrisdavies Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi Guys,

    I am really struggling with this so any help would be good. I have never used javascript before.

    The URL for the iframe if OS is mac: www.cerysrhysjones.co.uk/mac
    The URL for the iframe if OS is win: www.cerysrhysjones.co.uk/pc

    The script i have so far is this:

    <script type="text/javascript">
    if((navigator.platform.match("Mac"))) {
    window.frames[medialinks].src="www.cerysrhysjones.co.uk/mac"
    }
    else {
    window.frames[medialinks].src="www.cerysrhysjones.co.uk/pc"
    }
    </script>

    To be honest i am not sure that this works.

    Let me know what you think.

    Cheers

    CHRIS
     
    chrisdavies, Dec 7, 2009 IP
  5. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #5
    I believe this should work.

    Try implementing it and let us know if you face any difficulty in it..
     
    mastermunj, Dec 8, 2009 IP
  6. chrisdavies

    chrisdavies Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    cheers for all your help i managed to do it in the end after some tweaking. only problem i now have is that the iframe position will not move.

    Explanation:

    the website width is only 750px therefore you see a certain amount of the browser background - that is fine.

    I have set the position of the iframe but if i reduce the size of the window the iframe does not move but the rest of the site does.

    any help appreciated - i am sure it is something really silly that i am doing/not doing.

    CHRIS
     
    chrisdavies, Dec 10, 2009 IP