Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

launch function on page load as well and button press?

  • 06-01-2010 8:18pm
    #1
    Closed Accounts Posts: 6


    Presently the code on my site will, once the main image is clicked, check the screen resolution and then open a website depending on the one that best fits the webpage created for its dimension e.g. 1024x768, 800x600... I placed that dimension checking code into a function and then made the image a button to call it, but before I did that the code would automatically run when the user loads the page and I would like to get that back.

    How do I modify the code so that the resolution check and launching of the correct website happens on page load while also performing the same action if the main image is pressed on the page as now?

    http://www.meta.projectmio.com/pop.html

    Many thanks.


Comments

  • Registered Users, Registered Users 2 Posts: 11,989 ✭✭✭✭Giblet


    There are a number of ways, the easiest would probably to have a script tag with the function being called inside it.

    <script> function(); </script>

    Providing the function is within scope


  • Closed Accounts Posts: 6 oailon


    Many thanks for your prompt reply, I tried that but I obviously didn't do it right. The code on my site is very small so I'll paste it here if that's okay:

    Here is your idea:
    <script> dimension_test(); </script>
    

    Then I have the image which is a button:
    <div align="center">
    <img src="http://www.meta.projectmio.com/imagery/meta_popup.png" onclick= "dimension_test()" />
    </div>
    

    Then this code places the popup in the middle top of the users screen and defines the windows characteristics:
    <script>
    function PopupCenter(pageURL, title,w,h) {
    var left = (screen.width/2)-(w/2);
    var targetWin = window.open (pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
    }
    

    Finally is the function which checks the screen dimensions and lanches the appropriate page:
    function dimension_test() {
    var width = screen.width;var res =(((!(640-width))*1)+((!(800-width))*2)+((!(1024-width))*3)+((!(1152-width))*4)+((!(1280-width))*5)+((!(1600-width))*6)); 
    if(!(res)) res = 1;if (res=='1') {window.location='http://www.640.com/640_480.html'}
    if (res=='2') {window.location='http://www.86.com/800_600.html'}
    if (res=='3') {window.location='http://www.1024+.com/1024_768.html'}
    if (res!='1' && res!='2' && res!='3') PopupCenter ('http://www.meta.projectmio.com/800.html','MyWindow',800,531)
    }
    </script>
    

    Before (without the image being a button that called the function) the page would automatically behave as I needed, but Safari will not blindly launch popups so I thought that turning the page into a button which would demand it would work, it does, but at the expense of the automation on page load.

    So I need to fix that, but I could not get your suggestion to work.

    Many thanks.


  • Closed Accounts Posts: 6 oailon


    Ah, I called the function with an onload event:

    <BODY onLoad="dimension_test()">

    It works now :)

    Thanks for your help though!


Advertisement